Date: Thu, 18 Oct 2001 18:14 (6:14 p.m.) From: Mark Jacobson To: 810-080-01@uni.edu, 810-080-02@uni.edu Subject: Base 16 hexadecimal conversion.... > Is there any information hints on homework #5 about converting the > hexadecimal number to base 2 or 10. 1. Please see the web page http://www.cns.uni.edu/~jacobson/binary.txt easily found and linked to from http://www.cns.uni.edu/~jacobson/c080.html 2. Base 2 has 2 digits: 0 and 1 Base 10 has 10 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Base 16 has 16 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F In base 16, we have to invent 6 new digits, since human beings only have symbols for expressing the concepts 0, 1, ..., 8, 9 with a single symbol, with a single digit. Thus in base 16 we need to "INVENT" or agree on 6 more symbols so we can express 10, 11, 12, 13, 14 and 15 with ONE symbol or one base 16 digit. Why not use the upper-case letters of the alphabet, A, B, C, D, E, F? Okay. A is 10; B is 11; C = 12; D = 13; E = 14; F = 15 The largest quantity we can now express with a single digit is the value 15, which is F. Recall the largest of the ten decimal digits is 9, because 0 is the 1st of the ten base 10 digits. What is the hexadecimal number 2F when converted to base 10? 16 We are working in base 16. There are no ten dollar, one-hundred dollar or one-thousand dollar bills. 0 1 2 3 1 = 10 and 10 = 10 and 100 = 10 and 1000 = 10 ONE TEN HUNDRED THOUSAND 1s digit 10s digit 100s digit 1000s digit Base 16 has 1s, 16s, 256s and 4096s digits. 0 1 2 3 1 = 16 and 16 = 16 and 256 = 16 and 4096 = 16 1s digit 16s digit 256s digit 4096s digit It is base 16. 16 raised to some power. 0 1 2 3 1 = 16 and 16 = 16 and 256 = 16 and 4096 = 16 2F = 2 16s + F 1s = 2 16s + 15 1s = 32 + 15 = 47 16 10 Another example: What is the base 16 number AEC in base 10? A is the 256s digit E is the 16s digit C is the 1s digit A is 10 E is 14 C is 12 10 times 256 + 14 times 16 + 12 times 1 2560 + 224 + 12 = 2796 10 AEC = 2796 16 10 Convert AEC to binary? Method #1. Convert it to decimal. Then use your base 10 to binary conversion skills. Method #2. Use the following table and convert each base 16 Base 10 Base 16 Base 2 digit to its 4 binary digit 0 0 0000 value, then hook them all 1 1 0001 together. 2 2 0010 3 3 0011 4 4 0100 5 5 0101 6 6 0110 7 7 0111 8 8 1000 9 9 1001 ---- ---- 10 A 1010 <---- A = 10 = 1010 = 1 8s, 0 4s, 1 2s, 0 1s 11 B 1011 8 + 2 = 10 12 C 1100 13 D 1101 14 E 1110 15 F 1111 <---- F = 15 = 1111 = 1 8s, 1 4s, 1 2s, 1 1s 8 + 4 + 2 + 1 = 15 = F The largest value that can be stored in half a byte of memory, which is called a nybble of memory, is 1111 in binary, is F in hexadecimal. A byte of memory (which is two 4 bit nybbles), can be expressed with 2 base 16 digits instead of an unwieldy 8 binary digits! 11111111 can be expressed as FF or as 255 2 16 10 11101010 can be expressed as EA or as 234 2 16 10 AEC in binary is thus 1010 1110 1100 = 101011101100 16 AAAA EEEE CCCC 2 A E C A = 1010 = 10 E = 1110 = 14 C = 1100 = 12 2B8 = 0010 1011 1000 = 1010111000 (no need to put the leading 0s, 16 2 B 8 as they are insignificant zeros). I hope this helps. By the way, all web page colors are stored and expressed using base 16, hexadecimal digits. Each two digits represents value for one of three color components. RGB means Red, Green, and Blue BODY BGCOLOR="FF23DC" <----- Red = FF, Green = 23, Blue = DC 255 35 220 Past 810:080 Discrete Structures web pages FF is 255 for the amount of RED 23 is 2 * 16 + 3 = 35 for the amount of GREEN DC is 13 * 16 + 12 = 220 for the amount of BLUE RGB graphics -- -- -- One byte, two nybbles, 8 bits R G B for each color component. e r l d e u Often called 24 bit color. e e 3 * 8 = 24 binary digits n 3 bytes, 6 nybbles, 6 hexadecimal digits! Mark