Binary & Decimal numbers
Decimal system: Ten digits: 0,1,2,3,…,9 3185 Example: = 3*1000 + 1*100 + 8*10 + 5*1 = 3*103 + 1*102 + 8*101 + 5*100
10110 Binary system: Two digits: 0,1 Example: 1*(24) + 0*(23) + 1*(22) + 1*(21) + 0*(20)
Byte and Bit 1 Bit: (binary digit) either 0 or 1 Byte: an ordered collection of 8 bits 1 MSB (Most significant bit) LSB (Least significant bit)
Binary to Decimal 1 23 + 21 + 20 = 11 * 27 26 25 24 23 22 21 20 0*(27) 1 * 27 26 25 24 23 22 21 20 0*(27) 0*(26) 0*(25) 0*(24) 1*(23) 0*(22) 1*(21) 1*(20) 23 + 21 + 20 = 11
Decimal to Binary 25 1 [25%2=1] 12 [25/2=12] 0 [12%2=0] 6 [12/2=6] 0 [6%2=0] 3 [6/2=2] 1 [3%2=1] 1 [3/2=1] 1 [1%2=1] 0 [1/2=0] Right 1 2 3 4 5 6 7 8 9 Left 10 25 (decimal) = 11001 (binary)
Overflow 1 1 The highest number represented by 8 bits is 255 (why?). What happens when we add 1 to it? 1 The bit is lost !