Binary & Decimal numbers
3185 = 3* * *10 + 5*1 = 3* * * *10 0 Decimal system: Ten digits: 0,1,2,3,…,9 Example:
*(2 4 ) + 0*(2 3 ) + 1*(2 2 ) + 1*(2 1 ) + 0*(2 0 ) Binary system: Two digits: 0,1 Example:
Byte and Bit Bit: (binary digit) either 0 or 1 Byte: an ordered collection of 8 bits MSB (Most significant bit) LSB (Least significant bit)
*27*27 *26*26 *25*25 *24*24 *23*23 *22*222 *21*21 *20*20 Binary to Decimal *(2 7 )0*(2 6 )0*(2 5 )0*(2 4 )1*(2 3 )0*(2 2 )1*(2 1 )1*(2 0 ) = 11
Decimal to Binary 251 [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 Left 25 (decimal) = (binary)
Overflow The highest number represented by 8 bits is 255 (why?). What happens when we add 1 to it? The bit is lost !