You are on page 1of 4

Hex -> Binary

For this one, we're just going to follow the reverse procedure. Take each hex digit, find it's decimal equivalent, and then convert that small decimal number to a four-bit binary: Let's try 0x4B9: 9 in hex is also 9 in decimal. Following the procedure in the decimal->binary description, this comes out to 1001b B in hex is 11 in decimal. 11 decimal comes out to 1011b 4 in hex is 4 in decimal. 4 decimal comes out to 0100b Put all those blocks together: 0x4B9 = 010010111001

Hex -> Decimal
You have two choices here. The first, again involves knowing your powers of 16. For that, you'd take each hex digit, and multiply its decimal equivalent by the appropriate power of 16, then sum the results. So our example above: 0x4B9 would come out to: (9 x 1) + (11 x 16) + (4 x 256) As you can see, those are non-trivial computations. Instead, I rather strongly recommend you simply convert from Hex to Binary first, as above, and then follow the Binary->Decimal conversion algorithm to find your final result. Doing that, we find that 0100 1011 1001b comes out to: 1 + 8 + 16 + 32 + 128 + 1024 = 1209

To manually do base-10 to base-n conversions, go through the following steps: 1. Take your original base-10 number and divide it by your new base, n (2 or 16 for your examples, but it works with any base). 2. Prepend the remainder to your new number. If you haven’t been through this step before, then this becomes your least significant digit. 3. If the quotient is greater than the base, go back to step 1, using the new quotient instead of the original number. Otherwise, continue to step 4. 4. Append the quotient to the beginning of the new number. For example, let’s say your original base-10 number is 48879, and you want to convert to base-16. You would go through this process: 1. 48879 / 16 => quotient 3054, remainder 15 (written as "F"). 2. New number is F. 3. 3054 > 16, so go back to step 1. 1. 3054 / 16 => quotient 190, remainder 14 ("E"). 2. New number is EF. 3. 190 > 16, so go back to step 1.

1

Numbering system

so new number is 8669+65536 = 74205. so new number is 13+208 = 221. 13*16° = 13. Previous digit is 2. 2.) 1. remainder 14 ("E"). 201 is odd. so new number is 001. Now. Previous digit is 1. 4. and you’re done.5. Go back to step 1. so go on to step 4. The other way is to start at the beginning of the number: 2 Numbering system . 6 is even. For example. Take the last digit of your base-n number. 25 is odd. 3. 2. otherwise prepend a "0". 3/2 is 1. and throw away the remainder (you already handled it). Otherwise. (I’ll omit this step from the listings until we’re left with one. so we’re done. we follow a little different procedure. so new number is 221+256 = 477. and you can use whichever makes the most sense to you.5. 50/2 is 25. 1. beefy. 25/2 is 12. this formula can be simplified a bit: 1. 13*16¹ = 208. 190 / 16 => quotient 11. 2. so new number is 1001001. 2. 2. prepend a "1" to your new number. If your original base-10 number is odd. 100 is even. 2. For base-10 to base-2 (binary) specifically. Previous digit is 1. so new number is 01001. If you are left with 1. 11 < 16. For example. multiply the previous digit by n to the next higher power. and we’re done. there are two ways to approach this. 1*16² = 256. so use 1. 201/2 is 100. so new number is 13. to convert from base-n to base-10. 2. 2*16³ = 8192. 12/2 is 6. 2. 3. Actually. and multiply it by n°. so new number is 1. so use 100. 3 is odd. 2. go back to step 1. 2. 3. 2. so use 12. then prepend a "1" to your new number. so new number is BEEF. 6/2 is 3. New number is EEF. 1. 11 is written as "B". While there’s another digit. 2. so new number is 477+8192 = 8669.1. 1. 1. Since we’re left with 1. Mmm. and you want to convert it to binary. 2. 50 is even. Divide your base-10 number by two. Previous digit is D. so new number is 001001. 1. let’s say your original decimal number is 201. No more digits. 3. 1. 12 is even. 100/2 is 50. the new number is 11001001. then add that to your new number. This becomes your initial new number. so new number is 01. to convert the hexadecimal 121DD to decimal: 1. 2. 1*16^4 = 65536. so new number is 1001. Last digit is D (13). 2.5. 1.

This becomes your initial new number. No more digits. 2. Starting from the last digit. Hexadecimal Binary Digits 0 0000 1 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 0111 8 1000 9 1001 A 1010 B 1011 C 1100 D 1101 E 1110 F 1111 If you have the hexadecimal number FACE. since there is a direct conversion between the digits. 2. but you can prepend zeroes to make it a full four. For example. Converting from binary to hex is only very slightly more complicated. so new number is 1. Now. so FACE=1111101011001110. so new number is (16*4637)+13 = 72405. if you have the binary number 11010010001000001000000001. C=1100. Next digit is 2. so new number is (16*1)+2 = 18. Using the same example: 1. Next digit is 1. you can convert it to binary by directly substituting the corresponding values: F=1111. You may not complete with a full set. so new number is (16*289)+13 = 4637. E=1110. so new number is (16*18)+1 = 289. Next digit is D. 2. Next digit is D. converting between decimal and hexadecimal directly is actually quite a bit easier than using decimal as an intermediate step. inserting spaces every fourth digit: 11 0100 1000 1000 0010 0000 3 Numbering system . Take the first digit of your base-n number. 2. so we’re done. A=1010.1. 2. you start at the end and work your way backwards. First digit is 1. separate the digits into blocks of four. While there’s another digit. multiply your original number by n. then add the next digit to it.

3. you prepend two zeroes to make four digits (0011). String the remainders together: 100 decimal = 64 hex Decimal to binary: Same idea. that's the binary number. example: decimal number is 100. for example write 5 as 0101. String them together: 1010 0101 1001 and take out the spaces. Take dividend. Decimal to hex: 1. but divide by 2 each time and collect remainders. it will help to add leading zeros so that each number is expressed as 4 bits. next column binary. Then just substitute as above. 1010. (You need to know these like you know your decimal multiplication facts. Group the binary digits in fours. Make yourself a table going from 0 to 15 with one column decimal. example: 6/16 = 0 remainder 6. find remainder. 4. Replace the digit a by its binary equivalent. Replace 5 by 0101. third column hex. use table to find hex digit. For example. Binary to hex is just as easy. Example: 10110 = 16 + 4 + 2 = 22 4 Numbering system . replace each group of four using your table. add the results. 100/16 = 6 remainder 4. Since your last set only has two digits (11). Conversion between binary and hex is simply regrouping. conversion to/from decimal shows the general process Conversion from hex to binary is quite easy. 2. Let's say the hex number is a59. Divide decimal number by 16 and find remainder. Replace 9 by 1001.0001. Binary to decimal: Make yourself a table of powers of 2. divide by 16 if necessay. which gives you 3488201 in hex. Continue until dividend is 0. make is a hex digit.) Look up each place value 1 of the binary number. the eleventh row will be: 10 1010 a In the second column.