Binary Binary Binary Number System Binary Number System Binary to Decimal Binary to Decimal Decimal to Binary Decimal to Binary Octal and Hexadecimal Octal and Hexadecimal Binary to Hexadecimal Binary to Hexadecimal Hexadecimal to Binary Hexadecimal to Binary Hexadecimal to Decimal Hexadecimal to Decimal Any Number Base to Decimal Any Number Base to Decimal Decimal to Any Number Base Decimal to Any Number Base Binary Coded Decimal (BCD) Binary Coded Decimal (BCD)
A computer is a “bistable” device A bistable device: ◦ Easy to design and build ◦ Has 2 states: 0 and 1 One Binary digit (bit) represents 2 possible states (0, 1)
With 2 bits, 4 states are possible (2 2 = 4) With n bits, 2 n states are possible With 3 bits, 8 states are possible (2 3 = 8) Bit 1 Bit 0 State Bit 2 Bit 1 Bit 0 State Go back
From left to right, the position of the digit indicates its magnitude (in decreasing order) ◦ E.g. in decimal, 123 is less than 321 ◦ In binary, 011 is less than 100 A subscript indicates the number’s base ◦ E.g. is 100 decimal or binary? We don’t know! ◦ But = is clear Go back
Binary is base 2 Example: convert (binary) to decimal = 1x x x x x2 0 = 1x16 + 0x8 + 1x4 + 1x2 + 0x1 = =22 So = Go back
Binary is base 2 Example: convert 35 (decimal) to binary QuotientRemainder 35 / 2 = / 2 = 81 8 / 2 = 40 4 / 2 = 20 2 / 2 = 10 1 / 2 = 01 So = Go back
It is difficult for a human to work with long strings of 0’s and 1’s Octal and Hexadecimal are ways to group bits together Octal: base 8 Hexadecimal: base 16
With 4 bits, there are 16 possibilities Use 0, 1, 2, 3, …9 for the first 10 symbols Use a, b, c, d, e, and f for the last 6 Bit 3 Bit 2 Bit 1 Bit 0 Symbol a 101 1b 110 0c 110 1d 111 0e 111 1f Go back
= ? in hex Group into 4 bits, from the right: 0101, 0110, 1011, Now translate each (see previous table): => 5, => 6, => b, => 3 So this is 56b3 16 What if there are not enough bits? ◦ Pad with 0’s on the left Go back
f0e5 16 = ? in binary Translate each into a group of 4 bits: f 16 => , 0 16 => , e 16 => , 5 16 => So this is Go back
Hexadecimal is base 16 Example: convert 16 (hex) to decimal = 1x x16 0 = 1x16 + 6x1 = =22 So = Not surprising, since = 0001, ◦ If one of the hex digits had been > 9, say c, then we would have used 12 in its place. Go back
From right to left, multiply the digit of the number-to-convert by its base position Sum all results Go back
Take the decimal number, and divide by the new number base Keep track of the quotient and remainder Repeat until quotient = 0 Read number from the bottom to the top Go back
Why not use 4 bits to represent decimal? Let 0000 represent 0 Let 0001 represent 1 Let 0010 represent 2 Let 0011 represent 3, etc. ◦ This is called BCD ◦ Only uses 10 of the 16 possibilities Go back