Você está na página 1de 10

CONVERTING DECIMAL TO HEXADECIMAL

Steps: 1. 2. 3. 4. 5. Divide the decimal number by 16. Treat the division as an integer division. Write down the remainder (in hexadecimal). Divide the result again by 16. Treat the division as an integer division. Repeat step 2 and 3 until result is 0. The hex value is the digit sequence of the remainders from the last to first.

Note: a remainder in this topic refers to the left over value after performing an integer division. HEXADECIMAL 0 DECIMAL 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 A B C D E F

10 11 12 13 14 15

Example 1 Convert the number 1128 DECIMAL to HEXADECIMAL NOTES Start by dividing the number by 16, that is (1128/16). 1128 divided by 16 is 70.5. So the integer division result is 70 (throw out anything after the decimal point). Record it on the RESULT column. The remainder is (70.5 - 70) multiplied with 16; or (0.5 times 16), which is 8. Record it on the REMAINDER column. Then, divide the result again by 16, that is (70/16). (the number 70 on the DIVISION column comes 70 / 16 4 6 DIVISION RESULT REMAINDER (in HEXADECIMAL)

1128 / 16

70

from the previous RESULT). In this case, 70/16=4.375. So the integer division result is 4 (throw out anything after the decimal point) The remainder is (0.375 multiplied with 16, which is 6. Repeat. Note here that 4/16=0.25. So the integer division result is 0. 4 / 16 The remainder is (0.25-0) multiplied with 16, which is 4. Stop because the result is already 0 (0 divided by 16 will always be 0) Well, here is the answer. These numbers come from the REMAINDER column values (read from bottom to top) 0 4

468

Side note: You can get the remainder of a division using the Modulus (or % operator in programming code). Ie: 1128%16=8.

Example 2 Convert the number 256 DECIMAL to HEXADECIMAL DIVISION 256 / 16 16 / 16 1 / 16 ANSWER RESULT 16 1 0 REMAINDER (in HEX) 0 0 1 100

Example 3 Convert the number 921 DECIMAL to HEXADECIMAL DIVISION 921 / 16 57 / 16 3 / 16 ANSWER RESULT 57 3 0 REMAINDER (in HEX) 9 9 3 399

Example 4 Convert the number 188 DECIMAL to HEXADECIMAL REMAINDER DIVISION RESULT (in HEX) 188 / 16 11 / 16 ANSWER 11 0 C (12 decimal) B (11 decimal) BC

Note that here, the answer would not be 1112, but BC. Remember to write down the remainder in hex, not decimal.

Example 5 Convert the number 100 DECIMAL to HEXADECIMAL DIVISION 100 / 16 6 / 16 ANSWER RESULT 6 0 REMAINDER (HEX) 4 6 64

Example 6 Convert the number 590 DECIMAL to HEXADECIMAL

DIVISION 590 / 16 36 / 16 2 / 16 ANSWER

RESULT 36 2 0

REMAINDER (HEX) E (14 decimal) 4 (4 decimal) 2 (2 decimal) 24E

CONVERTING HEXADECIMAL TO DECIMAL


Steps: 1. 2. 3. 4. 5. 6. 7. Get the last digit of the hex number, call this digit the currentDigit. Make a variable, let's call it power. Set the value to 0. Multiply the current digit with (16^power), store the result. Increment power by 1. Set the the currentDigit to the previous digit of the hex number. Repeat from step 3 until all digits have been multiplied. Sum the result of step 3 to get the answer number.

Example 1 Convert the number 1128 HEXADECIMAL to DECIMAL MULTIPLICATION RESULT NOTES Start from the last digit of the number. In this case, the number is 1128. The last digit of that number is 8. Note that any number the power of 0 is always 1 Also note the notation (16^0) means 160, and (16^1) means 161, and (16^2) means 162, and so on. Process the previous, which is 2. Multiply that number with an increasing power of 16. Process the previous digit, which is 1, note that 16^2 means 162 or 16 x 16 Process the previous digit, which is 1, note that 16^3 means 16 x 16
4

8 x (16^0)

2 x (16^1)

32

1 x (16^2) 1 x (16^3)

256 4096

x 16 Here, we stop because there's no more digit to process ANSWER 4392 This number comes from the sum of the RESULTS (8+32+256+4096)=4392

Once discerned, notice that the above process is essentially performing this calculation: 1x(16^3) + 1x(16^2) + 2x(16^1) + 8x(16^0) When doing this by hand, it is easier to start backward is because:

Counting the number of digits takes extra time, and you might count wrongly. If you don't remember what a particular value of 16 to the power of n, it's easier to calculate it from the previous power of n value. For instance, if you don't remember what the value of 16^3 is, then just multiply the value of 16^2 (which you'll likely already have if you started backward) with 16.

Example 2 Convert the number 589 HEXADECIMAL to DECIMAL MULTIPLICATION 9 x (16^0) 8 x (16^1) 5 x (16^2) ANSWER RESULT 9 128 1280 1417

If you want to be a speed counter, it's beneficial to memorize the values of the smaller power of 16s, such as in this table POWER OF 16s 16^0 16^1 = 16 16^2 = 16x16 16^3 = 16x16x16 16^4 = 16x16x16x16 RESULT 1 16 256 4096 65536

Example 3 Convert the number 1531 HEXADECIMAL to DECIMAL (This time, let's use the table of the power-of-16s above.) MULTIPLICATION 1x1 3 x 16 5 x 256 1 x 4096 ANSWER RESULT 1 48 1280 4096 5425

Example 4 Convert the number FA8 HEXADECIMAL to HEXADECIMAL MULTIPLICATION 8x1 A x 16 (remember that hex A=decimal 10) F x 256 (remember that hex F=decimal 15) ANSWER RESULT 8 160 3840 4008

Example 5 Convert the number 8F HEXADECIMAL to DECIMAL DIVISION Fx1 8 x 16 ANSWER RESULT 15 128 143

Example 6 Convert the number A0 HEXADECIMAL to DECIMAL DIVISION 0x1 A x 16 RESULT 0 160

ANSWER

160

Example 7 Convert the number 12 HEXADECIMAL to DECIMAL DIVISION 2x1 1 x 16 ANSWER RESULT 2 16 18

Example 8 Convert the number 35432 HEXADECIMAL to DECIMAL 2x(16^0) + 3x(16^1) + 4x(16^2) + 5x(16^3) + 3x(16^4) = 2 + 3x16 + 4*256 + 5*4096 + 3*65536 = 2 + 48 + 1024 + 20480 + 196608 = 218162

CONVERTING HEXADECIMAL TO BINARY AND VICE VERSE THE EASY WAY


Converting hex number to binary number is very easy, it's almost trivial. The only requirement is that you know the equivalent binary value of each hexadecimal "digit" (0 to F); or if not, you must know how to convert them by hand. Below is a table that show each hexadecimal digit with it's corresponding binary number. Note that every binary number on this table consists of four digits. This is necessary because the maximum hexadecimal digit value is F or 15, which translates to four-digits-binary 1111. HEX 0 1 2 3 BINARY 0000 0001 0010 0011
7

4 5 6 7 8 9 A B C D E F

0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111

(Technically, any trailing 0 at the beginning of a number doesn't mean anything. So, binary 0010 is the same as binary 10, but for conversion purpose, include the trailing 0s.) To convert a hexadecimal number to binary. Just write down the binary value of each hex digit. Example 1: To convert hexadecimal F8 to binary, write down the binary for F first, then the binary for 8. F 8 1111 1000

So, the answer is 11111000. This seems too easy, and it is. Use a calculator to convince yourself. Another example: Convert hex number 1A to binary. 1 A 0001 1010 So, the answer is 00011010. (Note: Once you got the answer, you can ignore the zeros at the beginning, so this can be also written as 11010.) More examples: hex D C C bin 1101 1100 1100

hex 1 0 0 3 bin 0001 0000 0000 0011 hex F 3 A 2 bin 1111 0011 1010 0010

Binary to Hex Example: This time, let's assume we have a binary number that needs to be converted to hex. For example, the binary number 11010. In this case because the number of digits is not a multiple of 4, insert 0s at the beginning to make the number multiple of four. So it becomes 00011010. We then separate each four-digits pair and get their corresponding hex values. 0001 1010 1 A So, the answer is 1A. Memorizing the Table? I don't recommend memorizing the binary number of each hex digit. Also, if you don't know where those 0s and 1s comes from, it's easy to make mistakes and not knowing it, or even forget. I recommend that you know where they come from, and you won't have to worry much about forgetting. For example, know that 4 is 2^2, so the binary of 4 must be 0100. Why? Let's convert it systematically: DIVISION 4/2 2/2 1/2 RESULT 2 1 0 REMAINDER 0 0 1

The answer is the remainders being read backward, which is 100. 4 = (0)*2^3 + (1)*2^2 + (0)*2^1 + (0)*2^0 Realize that this is the only way the number 4 in binary can be represented. ANumber = (b1)*(2^3) + (b2)*(2^2) + (b3)*(2^1) + (b4)*(2^0) or ANumber = (b1)*8 + (b2)*4 + (b3)*2 + (b4)*1 where b1, b2, b3, b4 must be either 1 or 0.

So, let's say we're looking for the binary of 9. What sequence of bs will sum to 9? There's always one unique answer: 9 = (1)*8 + (0)*4 + (0)*2 + (1)*1 b1=1 b2=0 b3=0 b4=1 So the binary of 9 is 1001. How about the binary of 7. What sequence of bs will sum to 7? Again, there's only one answer: 7 = (0)*8 + (1)*4 + (1)*2 + (1)*1 b1=0 b2=1 b3=1 b4=1 So the binary of 7 is 0111.I've added a decimal column to the table; it's shown below. See Converting Binary. HEX 0 1 2 3 4 5 6 7 8 9 A B C D E F DECIMAL 0 = 0+0+0+0 1 = 0+0+0+1 2 = 0+0+2+0 3 = 0+0+2+1 4 = 0+2+0+0 5 = 0+4+0+1 6 = 0+4+2+0 7 = 0+4+2+1 8 = 8+0+0+0 9 = 8+0+0+1 10 = 8+0+2+0 11 = 8+0+2+1 12 = 8+4+0+0 13 = 8+4+0+1 14 = 8+4+2+0 15 = 8+4+2+1 BINARY 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111

10

Você também pode gostar