When searching for how to convert decimal numbers to hexadecimal it may seem like a daunting task. Until you learn about modulo.
The easiest way for me to count in Hex is by counting in decimal and converting to Hexadecimal using the modulo operator(like a programmer).
We take the remainders going from the latest remainder to the one we got first. In this case 3 5(the order is important).
Then we use this table to translate the remainders into hex
Now we translate the result into hex using the table and concatenate the result.
3 turns into 3
5 turns into 5
The result is 3 5 and when concatenated the final result is 35. In order to indicate its a hex number you write "#" symbol. So #35 is the equivalent of 53dec(decimal).
More Examples:
The easiest way for me to count in Hex is by counting in decimal and converting to Hexadecimal using the modulo operator(like a programmer).
- First you divide the decimal number by 16
- Math.floor() the Division Result
- Find the Division Remainder using modulo
- Divide the number of your Division Result by 16
- Repeat the previous steps until your Division Result is 0
| Divide | Division Result | Division Remainder |
|---|---|---|
| 53 / 16 | Math.floor(3.3125) = 3 | 53 % 16 = 5 |
| 3 / 16 | Math.floor(0.1875) = 0 | 3 % 16 = 3 |
Then we use this table to translate the remainders into hex
| Decimal value | Hex Equivalent |
|---|---|
| 1 | 1 |
| 2 | 2 |
| 3 | 3 |
| 4 | 4 |
| 5 | 5 |
| 6 | 6 |
| 7 | 7 |
| 8 | 8 |
| 9 | 9 |
| 10 | A |
| 11 | B |
| 12 | C |
| 13 | D |
| 14 | E |
| 15 | F |
5 turns into 5
The result is 3 5 and when concatenated the final result is 35. In order to indicate its a hex number you write "#" symbol. So #35 is the equivalent of 53dec(decimal).
More Examples:
- Remainders 12 15 3 turn into #CF3
- Remainders 5 10 14 turn into #5AE
Comentarios
Publicar un comentario