Unit 18: Computational Thinking Number systems
Bits and bytes A 4 bit number looks like this: 1 bit = a binary digit A 4 bit number looks like this: 1001 How many possible different 4 bit numbers are there? Hint: work out the minimum and maximum in decimal 0000 1111
Bits and bytes A 4 bit number has 16 different possible values It has 2*2*2*2 or 2 to the power 4 combinations 2*2*2*2 = 16 A byte has 8 bits How many different possible combinations?
Bytes 2 to the power 8 2*2*2*2*2*2*2*2 = 256 Minimum = 00000000 Maximum = 11111111 Writing bytes in binary is: Tedious Error-prone
Hexadecimal to the rescue! Makes life easier Now count to 15 using a single digit 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 That was easy – just like decimal! What about 10 and up? 10 = A 14= E 11= B 15= F 12= C 16= 10 (We now need 13= D an extra place value)
Hexadecimal
Hexadecimal So instead of 4 bits we have 1 hexadecimal digit 8 bits = 2 4 bit sections Convert each to hex Now have 256 = 1 byte = 2 hex digits
Conversion to hex Start with decimal number e.g. 36 Convert to binary = 32 (2*2*2*2*2)+4(2*2) = 00100100 as binary Split into 2 4-bit sections 0010 and 0100 (written as 0010 0100) Convert each 4-bit section to hex 0010 = 2, 0100 = 4 36 decimal = 00100100 binary = 24 hex
Try it yourself Convert the following decimal numbers to binary and then to hexadecimal. 34 63 127 244 57 98 Convert the following hexadecimal numbers to binary and then to decimal CC 33 AF 1F 8E FE
What about letters then? ASCII American Standard Code for Information Interchange ITF