2Outcome Familiar with the binary system Binary to Decimal and decimal to binaryArithmetic and logic operation in binary systemLogic gatesHalf Adder and Full AdderHexadecimal system
3Reading Goldsmiths Study guide: mathematics for computing
4The Decimal Number System (con’t) The decimal number system is also known as base 10. The values of the positions are calculated by taking 10 to some power.Why is the base 10 for decimal numbers?Because we use 10 digits, the digits 0 through 9.
5The Binary Number System – base 2 The decimal number system is a positional number system with a base 10.Example: 56235623 = = 5 x x x x 10050006002035 x 1036 x1022 x 1013 x 100
6The Binary Number System The binary number system is also known as base 2. The values of the positions are calculated by taking 2 to some power.Why is the base 2 for binary numbers?Because we use 2 digits, the digits 0 and 1.
7The Decimal Number System - base 10 The decimal number system is a positional number system with a base 10.Example: 101110112 = = 1 x x x x 20 = 111010000001011 x 230x221 x 211x 20
8Why Bits (Binary Digits)? Computers are built using digital circuitsInputs and outputs can have only two valuesTrue (high voltage) or false (low voltage)Represented as 1 and 0Can represent many kinds of informationBoolean (true or false)Numbers (23, 79, …)Characters (‘a’, ‘z’, …) ASCII, UNICODEPixelsSoundCan manipulate in many waysRead and writeLogical operationsArithmetic…
9Base 10 and Base 2 Base 10 Base 2 Each digit represents a power of 10 = 5 x x x x x 100Base 2Each bit represents a power of 2101012= 1 x x x x x 20 = 2110
10Converting from Binary to Decimal X 20 = 1X 21 = 01 X 22 = 420 = X 23 = 821 = X 24 = 022 = X 25 = 023 = X 26 = 6424 =25 = 3226 = 64
11Converting from Binary to Decimal (con’t) Practice conversions: Binary Decimal
12Converting From Decimal to Binary (con’t) Make a list of the binary place values up to the number being converted.Perform successive divisions by 2, placing the remainder of 0 or 1 in each of the positions from right to left.Continue until the quotient is zero.Example: 421042/2 = and R = 021/2 = and R = 110/2 = and R = 05/2 = 2 and R = 12/2 = 1 and R = 01/2 = 0 and R = 1=
13Example 1710We repeatedly divide the decimal number by 2 and keep remainders17/2 = and R = 18/2 = 4 and R = 04/2 = 2 and R = 02/2 = 1 and R = 01/2 = 0 and R = 1The binary number representing 17 is
14Converting From Decimal to Binary (con’t) Practice conversions: Decimal Binary
15Fractional Numbers Decimal = 4 x x x x x 10-2Binary= 1 x x x x x x 2-2= / ¼= =
16Binary Fractional to decimal nNumbers (cont) Example1= 1 x x x x x x 2-2= / ¼= =Example 2:= 1 x x x x x 2-2= / ¼ =Example3: = 1 x x x x x 2-3= ¼ /8 =
17Fractional numbers 4 2 1 Examples: 7.7510 = (?)2 Conversion of the integer part: same as before – repeated division by 27 / 2 = 3 (Q), 1 (R) 3 / 2 = 1 (Q), 1 (R) 1 / 2 = 0 (Q), 1 (R) = 1112Conversion of the fractional part: perform a repeated multiplication by 2 and extract the integer part of the result0.75 x 2 =1.50 extract 10.5 x 2 = extract = 0.112 stop Combine the results from integer and fractional part, =How about choose some ofExamples: try 5.625write in the same order4211/21/41/8=0.5=0.25=0.125
18Fractional Numbers (cont.) Exercise 3: Convert (0.8125)10 to its binary formSolution:x 2 = extract 10.625 x 2 = extract 10.25 x 2 = extract 00.5 x 2 = extract 1 stop (0.8125)10 = (0.1101)2
19Representing fraction with error Example: Convert (0.6)10 to its binary form0.6 x 2 = 1.2 extract 10.2 x 2 = 0.4 extract 00.4 x 2 = 0.8 extract 00.8 x 2 = 1.6 extract 10.6 x 2 = (0.6)10 = ( …)2
20Fractional Numbers (cont.) ErrorsOne source of error in the computations is due to back and forth conversions between decimal and binary formatsExample: (0.6)10 + (0.6)10 = 1.210Since (0.6)10 = ( …)2Lets assume a 8-bit representation: (0.6)10 = ( )2 , thereforeLets reconvert to decimal system:( )b= 1 x x x x x x x x x 2-8= 1 + 1/8 + 1/16 + 1/128 = Error = 1.2 –=
21Bits, Bytes, and Words A bit is a single binary digit (a 1 or 0). A byte is 8 bitsA word is 32 bits or 4 bytesLong word = 8 bytes = 64 bitsQuad word = 16 bytes = 128 bitsProgramming languages use these standard number of bits when organizing data storage and access.
22Adding Two Integers: Base 10 From right to left, we add each pair of digitsWe write the sum, and add the carry to the next column0 1 1SumCarry1 9 8SumCarry46121111
30Bitwise Operators: Shift Left/Right Shift left (<<): Multiply by powers of 2Shift some # of bits to the left, filling the blanks with 0Shift right (>>): Divide by powers of 2Shift some # of bits to the rightFor unsigned integer, fill in blanks with 0What about signed integers? Varies across machines…Can vary from one machine to another!15353<<25311153>>2111
31Boolean Algebra to Logic Gates Logic circuits are built from components called logic gates.The logic gates correspond to Boolean operations +, *, ’.Binary operations have two inputs, unary has oneOR+AND*NOT’
454-bit Ripple Adder using Full Adder CinCoutSS3A3B3CarryFullAdderABCinCoutSS2A2B2FullAdderABCinCoutSS1A1B1A0B0FullAdderABCinCoutSABCinCoutSH.A.Full AdderS0ABSCHalf Adder
46Working with Large Numbers = ?Humans can’t work well with binary numbers; there are too many digits to deal with.Memory addresses and other data can be quite large. Therefore, we sometimes use the hexadecimal number system.
47The Hexadecimal Number System The hexadecimal number system is also known as base 16. The values of the positions are calculated by taking 16 to some power.Why is the base 16 for hexadecimal numbers ?Because we use 16 symbols, the digits 0 and 1 and the letters A through F.
48The Hexadecimal Number System (con’t) Binary Decimal Hexadecimal Binary Decimal HexadecimalABCDEF
49The Hexadecimal Number System (con’t) Example of a hexadecimal number and the values of the positions:3 C B
50Example of Equivalent Numbers Binary:Decimal:Hexadecimal: 50A716Notice how the number of digits gets smaller as the base increases.
51Summary Convert binary to decimal Decimal to binary Binary operation Logic gatesUse of logic gates to perform binary operationsHalf adderFull adderThe need of Hexadecimal Hexadecimal
52Next lecture (Data representation) Put this all togethernegative and positive integer representationunsigned notationSigned notationExcess notationTow’s complement notationFloating point representationSingle and double precisionCharacter, colour and sound representation