CSC 2400 Announcements q HW 1 assigned (Due Wednesday) q Sign up for Piazza (30/47)
CSC 2400: Computer Systems Number Systems
Analog vs. Digital System q Analog Signals - Value varies continuously q Digital Signals - Value limited to a finite set - Digital systems more robust q Binary Signals - Has at most 2 values - Used to represent bit values - Bit time T needed to send 1 bit
Why Bits (Binary Digits)? q Computers are built using digital circuits - Inputs and outputs can have only two values - True (high voltage) or false (low voltage) - Represented as 1 and 0 q Can represent many kinds of information - Boolean (true or false) - Numbers (23, 79, …) - Characters (‘a’, ‘z’, …) - Pixels, sounds - Internet addresses
Coding q A single binary input can have two values: 1 or 0 q More bits = more combinations 0 0 0 1 1 0 1 1
Coding q How many values can you represent on 3 bits? q What about n bits?
Binary Numbers q How do you figure out what the value of 1110 two is? - Same way you do for 4173 ten , for instance q Decimal (base 10) - Each digit represents a power of 10 - 4173 ten = 4 x 10 3 + _____________________ q Binary (base 2) - Each bit represents a power of 2 - 1110 two = 1 x 2 3 + _____________________ = 14 ten
Binary Numbers q How do you figure out what the value of 1110 two is? - Same way you do for 4173 ten , for instance q Decimal (base 10) - Each digit represents a power of 10 - 4173 ten = 4 x 10 3 + 1 x 10 2 + 7 x 10 1 + 3 x 10 0 q Binary (base 2) - Each bit represents a power of 2 - 1110 two = 1 x 2 3 + 1 x 2 2 + 1 x 2 1 + 0 x 2 0 = 14 ten
Counting in Binary Base 10 Base 2 0 = 0 1 = 1 2 = 10 3 = 11 4 = _____ 5 = _____ 6 = _____ 7 = _____ 8 = _____ 9 = _____ 10 = _____ 11 = _____ 12 = _____ 13 = _____ 14 = _____ 15 = _____ 16 = _____ 17 = _____ 18 = _____
Counting in Binary Base 10 Base 2 0 = 0000 0 1 = 0000 1 2 = 000 10 3 = 000 11 4 = 00 100 5 = 00 101 6 = 00 110 7 = 00 111 8 = 0 1000 9 = 0 1001 10 = 0 1010 11 = 0 1011 12 = 0 1100 13 = 0 1101 14 = 0 1110 15 = 0 1111 16 = 10000 17 = 10001 18 = 10010
Binary (Base 2) to Decimal q Sum up (bit*weight): 2 8 2 7 2 6 2 5 2 4 2 3 2 2 2 1 2 0 Binary Weights 256 128 64 32 16 8 4 2 1 1 0 0 0 0 0 1 1 1 0 1 0 0 1 1 0 0 10000011 two = _______________________________ ten ? 101001100 two = _______________________________ ten ?
Binary (Base 2) to Decimal q Sum up (bit*weight): 2 8 2 7 2 6 2 5 2 4 2 3 2 2 2 1 2 0 Binary Weights 256 128 64 32 16 8 4 2 1 1 0 0 0 0 0 1 1 1 0 1 0 0 1 1 0 0 10000011 two = _131___________________________ ten ? 101001100 two = _332___________________________ ten ?
Powers of 2 q Memorize! 2 10 2 9 2 8 2 7 2 6 2 5 2 4 2 3 2 2 2 1 2 0 1024 512 256 128 64 32 16 8 4 2 1 2 80 2 70 2 60 2 50 2 40 2 30 2 20 2 10 Yotta Zetta Exa Peta Tera Giga Mega Kilo Y Z E P T G M K
Number Systems Base Character Set 2 {0,1} 3 {0,1,2} 4 {0,1,2,3} 5 {0,1,2,3,4} 6 {0,1,2,3,4,5} 7 {0,1,2,3,4,5,6} 8 {0,1,2,3,4,5,6,7} 9 {0,1,2,3,4,5,6,7,8} 10 {0,1,2,3,4,5,6,7,8,9} 11 {0,1,2,3,4,5,6,7,8,9,A} 12 {0,1,2,3,4,5,6,7,8,9,A,B} 13 {0,1,2,3,4,5,6,7,8,9,A,B,C} 14 {0,1,2,3,4,5,6,7,8,9,A,B,C,D} 15 {0,1,2,3,4,5,6,7,8,9,A,B,C,D,E} 16 {0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F}
Counting in Octal Base 10 Base 8 0 = 0 1 = 1 2 = 2 3 = 3 4 = 4 5 = 5 6 = 6 7 = 7 8 = 10 9 = __ 10 = __ 11 = __ 12 = __ 13 = __ 14 = __ 15 = __ 16 = __ 17 = __ 18 = __
Counting in Octal Base 10 Base 8 0 = 0 00 1 = 1 00 2 = 2 00 3 = 3 00 4 = 4 00 5 = 5 00 6 = 6 00 7 = 7 00 8 = 10 0 9 = 11 0 10 = 12 0 11 = 13 0 12 = 14 0 13 = 15 0 14 = 16 0 15 = 17 0 16 = 20 0 17 = 21 0 18 = 22 0
Octal (Base 8) to Decimal q Sum up (digit*weight): 8 4 8 3 8 2 8 1 8 0 Octal weights 4096 512 64 8 1 2 5 7 1 0 2 2 6 257 8 = _________________________________ 10 ? 10226 8 = _________________________________ 10 ?
Octal (Base 8) to Decimal q Sum up (digit*weight): 8 4 8 3 8 2 8 1 8 0 Octal weights 4096 512 64 8 1 2 5 7 1 0 2 2 6 257 8 = _175_____________________________ 10 ? 10226 8 = _4246____________________________ 10 ?
Counting in Hexadecimal Base 10 Base 16 0 = 0 1 = 1 2 = 2 3 = 3 4 = 4 5 = 5 6 = 6 7 = 7 8 = 8 9 = 9 10 = A 11 = B 12 = C 13 = D 14 = E 15 = F 16 = 10 17 = __ 18 = __
Counting in Hexadecimal Base 10 Base 16 0 = 00 0 1 = 00 1 2 = 00 2 3 = 00 3 4 = 00 4 5 = 00 5 6 = 00 6 7 = 00 7 8 = 00 8 9 = 00 9 10 = 00 A 11 = 00 B 12 = 00 C 13 = 00 D 14 = 00 E 15 = 00 F 16 = 0 10 17 = 0 11 18 = 0 12
Hexadecimal (Base 16) to Decimal q Sum up (hex digit*weight): 16 3 16 2 16 1 16 0 Hexadecimal Weight 4096 256 16 1 A 2 B 1 4 A 6 A2B 16 = _________________________________ 10 ? 14A6 16 = _________________________________ 10 ?
Hexadecimal (Base 16) to Decimal q Sum up (hex digit*weight): 16 3 16 2 16 1 16 0 Hexadecimal Weight 4096 256 16 1 A 2 B 1 4 A 6 A2B 16 = _2603____________________________ 10 ? 14A6 16 = _5286____________________________ 10 ?
Decimal to Binary q Use the Placement Method Powers of 2 1024 512 256 128 64 32 16 8 4 2 1 155 10 = _________________________________ 2 ? 128 goes into 155 once leaving 27 to be placed 1 ? ? ? ? ? ? ? 64 and 32 are too big (make them 0) 16 goes in once leaving 11 1 0 0 1 ? ? ? ? and so on
Decimal to Binary q Use the Placement Method Powers of 2 1024 512 256 128 64 32 16 8 4 2 1 155 10 = _10011011________________________ 2 ? 128 goes into 155 once leaving 27 to be placed 1 ? ? ? ? ? ? ? 64 and 32 are too big (make them 0) 16 goes in once leaving 11 1 0 0 1 ? ? ? ? and so on
You Try It … Powers of 2 1024 512 256 128 64 32 16 8 4 2 1 583 10 = _________________________________ 2 ?
You Try It … Powers of 2 1024 512 256 128 64 32 16 8 4 2 1 583 10 = _1001000111______________________ 2 ?
Hexadecimal Benefits q It is often convenient to write binary (base-2) numbers as hexadecimal (base-16) numbers instead - fewer digits – four bits per hex digit - less error prone – easy to corrupt long string of 1’s and 0’s Binary Hex Decimal Binary Hex Decimal 0000 0 0 1000 8 8 0001 1 1 1001 9 9 0010 2 2 1010 A 10 0011 3 3 1011 B 11 0100 4 4 1100 C 12 0101 5 5 1101 D 13 0110 6 6 1110 E 14 0111 7 7 1111 F 15
Converting from Binary to Hexadecimal q Every four bits is a hex digit - start grouping from right-hand side 0 011101010001111010011010111 3 __ __ __ __ __ __ This is not a new machine representation, just a convenient way to write the number
Converting from Binary to Hexadecimal q Every four bits is a hex digit. - start grouping from right-hand side 0 011101010001111010011010111 3 A 8 F 4 D 7 This is not a new machine representation, just a convenient way to write the number
Exercises 1. Convert the hex value 0x7A8BF7D6 into its binary equivalent: A 8 7 7 B F D 6 0111 1010 ____ ____ ____ ____ ____ ____ 2. Convert the binary 10 0110 1110 1001 0100 1100 0101 1111 2 to hex: 0110 1110 0010 1001 0100 1100 0101 1111 2 6 __ __ __ __ __ __
Exercises 1. Convert the hex value 0x7A8BF7D6 into its binary equivalent: A 8 7 7 B F D 6 0111 1010 1000 1011 1111 0111 1101 0110 2. Convert the binary 10 0110 1110 1001 0100 1100 0101 1111 2 to hex: 0110 1110 0010 1001 0100 1100 0101 1111 2 6 E 9 4 C 5 F
Exercises (contd.) 3. Convert from binary to octal: 10 111 010 100 110 001 011 111 2 111 010 010 100 110 001 011 111 2 __ __ __ __ __ __ __
Exercises (contd.) 3. Convert from binary to octal: 10 111 010 100 110 001 011 111 2 111 010 010 100 110 001 011 111 2 7 2 4 6 1 3 7
Number Systems q The binary, hexadecimal (hex) and octal system share one common feature - they are all based on powers of 2 q Each digit in the hex system is equivalent to a four-digit binary number and each digit in the octal system is equivalent to a 3-digit binary number.
Practice Hex Decimal Binary 10 240 11111111
Practice Hex Decimal Binary 10 16 10000 F0 240 11110000 FF 255 11111111
Arithmetic Operations
Decimal Addition q From right to left, we add each pair of digits q We write the sum, and add the carry to the next column 1 9 8 + 2 6 4 4 6 2 Sum Carry 0 1 1
Hex Addition q Hex addition is similar to decimal addition except that each hex digit has a range of ‘ 0 ’ to ‘ F ’ instead of ‘0’ to ‘9’, and a “carry out” occurs when the sum of hex digits in a particular column exceeds ‘ F ’ (15 decimal). q Examples: 1 1 1 1 C 3 8 5 3 B 9 A C 7 + 2 7 + E D + D 2 E 6 + 2 A E A F 1 1 7 2 1 0 E 8 0
Binary Addition q From right to left, we add each pair of bits 0 + 0 = 0 0 + 1 = 1 1 + 0 = 1 1 + 1 = 10 q We write the sum, and add the carry to the next column Base 2 Base 10 (ten) 0 1 1 1 9 8 + 0 0 1 + 2 6 4 4 6 2 Sum Sum Carry Carry 0 1 1
Recommend
More recommend