INTRO

In this article, you will learn about hex and decimal. and you will learn to change the decimal to hex with basic Maths. Some of you may have an idea about the Number System in computers. well, A numeral system is a writing system for expressing numbers; that is, a mathematical notation for representing numbers of a given set, using digits or other symbols in a consistent manner. READ MORE…

Decimal and Hex are types of the Number System. Both of these are useful when you learn Assembly Language and microprocessors. You can say that Hex is a way to define Decimal in a simple way. It is not necessary to write values in Hex but Hex make it simple to read or write.

 

DECIMAL AND HEX

Decimal Number System starts at 0 and ends at 9. it wasn’t hard. was it?

Total Decimal Chars: 0 1 2 3 4 5 6 7 8 9

But Hex is a little bit odd. it is not hard but it is different. basically, Hex works on Base16. It means that instead of having ten chars it has 16 chars. So, the first ten chars are 0-9 and the last six chars are A-F.

Total Hex Chars: 0 1 2 3 4 5 6 7 8 9 A B C D F

Take these alphabet chars as numbers. for example:

A→ 10, B → 11, C →12, D → 13, E → 14, F → 15

Remember these values, we are going to use these to convert Decimal into Hex. but before we do that. let’s open python ide to check these values. Type this command:

python

and type 0xB and see if you got the 11 as a result.

Screenshot:

Try to change 11 into Hex value with python.

Screenshot:

 

Decimal to Hex

I think I have explained everything that is necessary to convert Decimal no. into Hex value.  one more thing, You should know the table of 16. yes, it is not a joke. I actually mean it.

let’s pick a number, for example, we want to convert 255 into hex. so, the first thing we will do is make an index that has Q on one side and R on the other side.

Do something like this:

Now divide the chosen number by 16. stop when you get the remainder and quotient. write the reminder in the R section and quotient in the Q.

Divide:

Index:

We got 15 as the reminder and 15 again as the quotient. Now, you need to remember this ” if the dividend is smaller than the divisor (Dividend<Divisor), put the dividend in R section.”

and if we do that we will have two 15 in R section.

Index:

 

But I have already told you that 15 is not any char is hex. 15 would be “f” in Hex. so, the value would be “0xff” in Hex. we can check it via python.

Let’s take another example. but this time let choose a big decimal number “1553”. so, create an index as we did in the previous example.

After dividing the “1553′ by 16, we will get 97 as quotient and 1 as a reminder. now dividend will be 97 and the divisor will be 16.

you will get new values. the quotient will be 6 and the new remainder will be 1. and I told you that if the new dividend or quotient is smaller than the divisor, we will put quotient in the R section.

But remember one thing here that we always read from the bottom. so, instead of the value being “116” it would be “611”. the Hex value for 1553 would be “0x611” .and that’s how we can get our hex value.

 

 

Thanks For Visiting.

LEAVE A REPLY

Please enter your comment!
Please enter your name here