Decimal numbers: Base 10 Digits:0,1,2,3,4,5,6,7,8,9 Example: 3271 (3x10)+(2x102)+(7X101)+1X109 Number Re presentation Garcia, Spring 2007
CS61C L02 Number Representation (6) Garcia, Spring 2007 © UCB Decimal Numbers: Base 10 Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Example: 3271 = (3x103 ) + (2x102 ) + (7x101 ) + (1x100 )
Numbers: positional notation Number Base B= B symbols per digit Base10( Decimal):0,1,2,3,4,5,6,7,8,9 Base 2 (Binary): 0, 1 Number representation 31030 d,do is a 32 digit number vaue=37XB31+030×B30+…+01 B1+d×B0 Binary: 0, 1 (n binary digits called"bits 0b11010=1×24+1×23+0×22+1×21+0×20 =16+8+2 #s often written =26 0b... Here 5 digit binary turns into a 2 digit decimal Can we find a base that converts to binary easily? CS61C L02 Number Re presentation Garcia, Spring 2007
CS61C L02 Number Representation (7) Garcia, Spring 2007 © UCB Numbers: positional notation • Number Base B B symbols per digit: • Base 10 (Decimal): 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Base 2 (Binary): 0, 1 • Number representation: • d31d30 ... d1d0 is a 32 digit number • value = d31 B31 + d30 B30 + ... + d1 B1 + d0 B0 • Binary: 0,1 (In binary digits called “bits”) • 0b11010 = 12 4 + 12 3 + 02 2 + 12 1 + 02 0 = 16 + 8 + 2 = 26 • Here 5 digit binary # turns into a 2 digit decimal # • Can we find a base that converts to binary easily? #s often written 0b…
Hexadecimal Numbers: Base 16 Hexadecimal 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F Normal digits 6 more from the alphabet In C, written as OX.(e.g., OXFAB5) Conversion: BinarysHex 1 hex digit represents 16 decimal values 4 binary digits represent 16 decimal values =1 hex digit replaces 4 binary digits One hex digit is a“ nibble". Two is a“byte” Example: 101011000011( binary)=0x CS61C L02 Number Re presentation(8 Garcia, Spring 2007
CS61C L02 Number Representation (8) Garcia, Spring 2007 © UCB Hexadecimal Numbers: Base 16 • Hexadecimal: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F • Normal digits + 6 more from the alphabet • In C, written as 0x… (e.g., 0xFAB5) • Conversion: BinaryHex • 1 hex digit represents 16 decimal values • 4 binary digits represent 16 decimal values 1 hex digit replaces 4 binary digits • One hex digit is a “nibble”. Two is a “byte” • Example: • 1010 1100 0011 (binary) = 0x_____ ?
Decimal vS Hexadecimal vs Binary Examples 0000000 0110001 101011000011 binary)0220010 OxAC3 033 0011 0440100 10111 (binary) 0550101 =00010111(6 bInary) 0660110 =0x17 0770111 0881000 0991001 0x3F9 1021010 =1111111001( binary)11B1011 2c1100 How do we convert between 13 D 1101 hex and Decimal? 14E1110 15F1111 MEMORIZE! CS61C L02 Number Re presentation(9) Garcia, Spring 2007
CS61C L02 Number Representation (9) Garcia, Spring 2007 © UCB Decimal vs. Hexadecimal vs. Binary Examples: 1010 1100 0011 (binary) = 0xAC3 10111 (binary) = 0001 0111 (binary) = 0x17 0x3F9 = 11 1111 1001 (binary) How do we convert between hex and Decimal? 00 0 0000 01 1 0001 02 2 0010 03 3 0011 04 4 0100 05 5 0101 06 6 0110 07 7 0111 08 8 1000 09 9 1001 10 A 1010 11 B 1011 12 C 1100 13 D 1101 14 E 1110 15 F 1111 MEMORIZE! Examples: 1010 1100 0011 (binary) = 0xAC3 10111 (binary) = 0001 0111 (binary) = 0x17 0x3F9 = 11 1111 1001 (binary) How do we convert between hex and Decimal?
Kilo, Mega, Giga, Tera, Peta, Exa, Zetta, Yotta physics. nist. gov/cuu/Units/binary.html Common use prefixes(all Sl, except K[k in SI] Name Abbr Factor sI size Kilo K|210=1,024 103=1,000 Mega M|20=1,048576 106=1,000,000 Giga G 230=1.073.741824 109=1,000,000,000 Tera T|240=1,099511627,776 1012=1,000,000,000,000 Peta P250=1,125,899,906,842,624 1015=1000000000,000.000 Exa E|20=1,152,921,504,606,846,976 1018=1,000,000,000,000,000,000 Zetta z20=118,591,0,717413424 1021=1000,00000000000000,000 YottaY|280=1,208,9258:19,614629,174,706,1761024=1,00000 Confusing! Common usage of“ kilobyte” means 1024 bytes, but the "correct"si value is 1000 bytes Hard Disk manufacturers Telecommunications are the only computing groups that use SI factors, so what is advertised as a 30 gb drive will actually only hold about 28 x 230 bytes, and a 1 Mbit/s connection transfers 106 bps CS61C L02 Number Re presentation(10) Garcia, Spring 2007
CS61C L02 Number Representation (10) Garcia, Spring 2007 © UCB Kilo, Mega, Giga, Tera, Peta, Exa, Zetta, Yotta • Common use prefixes (all SI, except K [= k in SI]) • Confusing! Common usage of “kilobyte” means 1024 bytes, but the “correct” SI value is 1000 bytes • Hard Disk manufacturers & Telecommunications are the only computing groups that use SI factors, so what is advertised as a 30 GB drive will actually only hold about 28 x 2 30 bytes, and a 1 Mbit/s connection transfers 106 bps. Name Abbr Factor SI size Kilo K 2 10 = 1,024 103 = 1,000 Mega M 2 20 = 1,048,576 106 = 1,000,000 Giga G 2 30 = 1,073,741,824 109 = 1,000,000,000 Tera T 2 40 = 1,099,511,627,776 1012 = 1,000,000,000,000 Peta P 2 50 = 1,125,899,906,842,624 1015 = 1,000,000,000,000,000 Exa E 2 60 = 1,152,921,504,606,846,976 1018 = 1,000,000,000,000,000,000 Zetta Z 2 70 = 1,180,591,620,717,411,303,424 1021 = 1,000,000,000,000,000,000,000 Yotta Y 2 80 = 1,208,925,819,614,629,174,706,176 1024 = 1,000,000,000,000,000,000,000,000 physics.nist.gov/cuu/Units/binary.html