Decimal Numbers: Base 10 Numbers: positional notation

Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 • 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 Example: • Number representation:

3271 = • d31d30 ... d1d0 is a 32 digit number • value = d " B31 + d " B30 + ... + d " B1 + d " B0 (3x103) + (2x102) + (7x101) + (1x100) 31 30 1 0 • Binary: 0,1 (In binary digits called “”) • 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 L01 Introduction + Numbers (33) Garcia, Fall 2005 © UCB CS61C L01 Introduction + Numbers (34) Garcia, Fall 2005 © UCB

Hexadecimal Numbers: Base 16 Decimal vs. vs. Binary

• Hexadecimal: Examples: 00 0 0000 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, , D, E, F 01 1 0001 1010 1100 0011 (binary) 02 2 0010 • Normal digits + 6 more from the alphabet = 0xAC3 03 3 0011 • In C, written as 0x… (e.g., 0xFAB5) 04 4 0100 10111 (binary) 05 5 0101 • Conversion: Binary!Hex 06 6 0110 = 0001 0111 (binary) 07 7 0111 • 1 hex digit represents 16 decimal values = 0x17 08 8 1000 • 4 binary digits represent 16 decimal values 09 9 1001 0x3F9 "1 hex digit replaces 4 binary digits 10 A 1010 = 11 1111 1001 (binary) 11 B 1011 • One hex digit is a “nibble”. Two is a “” 12 C 1100 How do we convert between 13 D 1101 • Example: hex and Decimal? 14 E 1110 15 F 1111 • 1010 1100 0011 (binary) = 0x_____ ? MEMORIZE! CS61C L01 Introduction + Numbers (35) Garcia, Fall 2005 © UCB CS61C L01 Introduction + Numbers (36) Garcia, Fall 2005 © UCB

Kilo, Mega, Giga, Tera, Peta, Exa, Zetta, Yotta kibi, mebi, gibi, tebi, pebi, exbi, zebi, yobi physics.nist.gov/cuu/Units/binary.html en.wikipedia.org/wiki/Binary_prefix • Common use prefixes (all SI, except K [= k in SI]) • New IEC Standard Prefixes [only to exbi officially] Name Abbr Factor SI size Name Abbr Factor Kilo K 210 = 1,024 103 = 1,000 kibi Ki 210 = 1,024 As of this Mega M 220 = 1,048,576 106 = 1,000,000 mebi Mi 220 = 1,048,576 writing, this Giga G 230 = 1,073,741,824 109 = 1,000,000,000 30 gibi Gi 2 = 1,073,741,824 proposal has Tera T 240 = 1,099,511,627,776 1012 = 1,000,000,000,000 tebi Ti 240 = 1,099,511,627,776 Peta P 250 = 1,125,899,906,842,624 1015 = 1,000,000,000,000,000 pebi Pi 250 = 1,125,899,906,842,624 yet to gain Exa E 260 = 1,152,921,504,606,846,976 1018 = 1,000,000,000,000,000,000 exbi Ei 260 = 1,152,921,504,606,846,976 widespread Zetta Z 270 = 1,180,591,620,717,411,303,424 1021 = 1,000,000,000,000,000,000,000 zebi Zi 270 = 1,180,591,620,717,411,303,424 use… Yotta Y 280 = 1,208,925,819,614,629,174,706,176 1024 = 1,000,000,000,000,000,000,000,000 yobi Yi 280 = 1,208,925,819,614,629,174,706,176 • International Electrotechnical Commission (IEC) in • Confusing! Common usage of “” means 1999 introduced these to specify binary quantities. 1024 , but the “correct” SI value is 1000 bytes • Names come from shortened versions of the • Hard Disk manufacturers & are original SI prefixes (same pronunciation) and bi is the only groups that use SI factors, so short for “binary”, but pronounced “bee” :-( what is advertised as a 30 GB drive will actually only hold about 28 x 230 bytes, and a 1 Mbit/s connection • Now SI prefixes only have their base-10 meaning 6 and never have a base-2 meaning. transfersCS61C L01 Introductio n10 + Num bbps.ers (37) Garcia, Fall 2005 © UCB CS61C L01 Introduction + Numbers (38) Garcia, Fall 2005 © UCB The way to remember #s

• What is 234? How many bits addresses (I.e., what!s ceil log2 = lg of) 2.5 TiB? • Answer! 2XY means… X=0 ! --- Y=0 ! 1 X=1 ! kibi ~103 Y=1 ! 2 X=2 ! mebi ~106 Y=2 ! 4 X=3 ! gibi ~109 Y=3 ! 8 X=4 ! tebi ~1012 Y=4 ! 16 X=5 ! pebi ~1015 Y=5 ! 32 X=6 ! exbi ~1018 Y=6 ! 64 X=7 ! zebi ~1021 Y=7 ! 128 X=8 ! yobi ~1024 Y=8 ! 256 Y=9 ! 512 MEMORIZE! CS61C L02 Number Representation (24) Garcia, Spring 2008 © UCB