Dec to hex converter

Dec to hex converter

Dec to hex converter (or a dec to hex convertor) is a tool used to convert numbers expressed in the decimal format into hexadecimal or short hex format. Dec to hex conversion is common when working with web sites and graphics.

Many graphic tools, utilities, and editors provide information in dec format while web sites are often coded using hex values for colors (see the Browser Safe Colors Palette).

Dec to hex converter / convertor

If you want to convert dec to hex, you are welcome to use our dec to hex converter. Our dec to hex convertor is provided below and works simply by entering your dec number in the input field.

Enter your dec or decimal number below:

Your decimal number expressed as bin (binary) is:

Your decimal number expressed as hex (hexadecimal) is:

Let's explain how the dec to hex convertor and dec to hex conversion works. But before we do so, did you know that every letter can be expressed as a number and that every color can also be expressed as a number? Take a look at our ASCII to hex converter (code ASCII) and RGB color mixer for more details. If you want to convert from hex to decimal, go to our hex to decimal converter.

Dec to hex conversion table

The dec to hex conversion table provided below can help you with manual dec to hex conversions. When converting dec to hex, first, convert dec to binary and then to hex. First, table for the first 4 bits.

Dec to Hex and Bin conversion table

Second, table for selected values from the 8 bits scheme.

Dec to Hex and Bin conversion table (expanded above 4 bits)

Now, let's take a look how the dec to hex converter works.

How the dec to hex converter and dec to hex conversion works

The logic behind the dec to hex convertor / converter is quite simple. Converting dec to hex is a two step process. First, you convert from dec to binary and then from binary to hex.

Let's take a look at a dec to hex conversion example. We will convert number 231. First, we convert this number into binary and then into hexadecimal. We know that every 1 in a byte translates to some decimal number and the other way around. For example, binary 00000001 is decimal 1. Binary 00000010 is decimal 2. Binary 00000011 is decimal 3. Binary 00000100 is decimal 4. You can see that the ones work their way from right to left. Why is it this way? Just because. Someone defined it this way.

We know that isolated ones in a byte are number 2 to some power. In other words 22 = decimal 4 = binary 00000100. 23 = decimal 8 = binary 00001000. 24 = decimal 16 = binary 00010000. 25 = decimal 32 = binary 00100000. 27 = decimal 128 = binary 1000000. See how the "1" isolated with zeros moves to the left.

We can add binary numbers the same way we add decimal numbers. In other words, decimal 128 + decimal 32 = decimal 160. When we look at this in binary, then it is 10000000 + 00100000 = 10100000. Now we apply this concept to our dec to hex conversion, we just approach it from the other end. We have 231, and we need to find out which bits in a byte go into it.

We can see that 231 includes one 128, so our binary result will include 1 in the first bit. 231-128 is 103. Number 103 includes 64 which is our second bit (1) in a byte. Now we know our byte will start with two ones 11??????. 103-64 is 39. This tells us we will include third bit in our byte for 32, now we know our binary byte will start with three ones 111?????. You can see this process pictured more clearly below.

Dec to hex converter

We calculated that dec 231 translates to binary 11100111.

Now we approach to the second step of the dec to hex conversion. Because each hex single digit goes up to 16 (0 to 15), it can be expressed as 4 bits. When looking at a byte (8 bits), it includes two hex digits (2 times 4 bits). The first 4 bits are 1110 and the remaining 4 bits are 0111 in our case. We can see in the table above that 4 bits 1110 equal hex E and 4 bits 0111 equal hex 7.

Dec to hex convertor

Thus, we conclude that dec 231 converted to hex is E7. You can try this dec to hex conversion in the dec to hex converter provided above.

Dec to hex converter in PHP

If you like to play with PHP and for some reason need to convert dec to hex in PHP, there is a function that does the dec to hex conversion for you. The name of the dec to hex conversion function is dechex(), and you would use it as follows:

echo dechex(10) . "\n";

Easy enough.

Any other fun stuff besides the dec to hex converter?

Yes, we have a lot of other interesting articles on our web site in addition to the dec to hex converter. Take a look at the following articles:

Hex to decimal converter
ASCII to hex converter (code ASCII)
Decimal to binary converter
RGB color picker
Word letter mixer (disorganizer)
How to blur text or image
PHP loop through string
PHP display array content
How to create Favicon
How to check if string contains substring PHP

You are welcome to ask any questions you may have about dec to hec conversion in our discussion forum.


Discuss this article or this topic in our discussion forum:
(The table bellow shows a list of 8 most recent topics posted in our discussion forum. Visit our discussion forum to see more. It is possible the links below are not related to this page, but you can be certain you will find related posts in the discussion forum. You can post one yourself too.)
Email this article to a friend:
2 + 6 - 3 = 
How can I link to this web page?

It is easy, just include the code provided below into your HTML code.

<a href="" title=" Dec to hex converter" target="_blank">Dec to hex converter</a>