Decimal Conversions

I am a recent graduate at the beginning of my software development career. I enjoy documenting my learnings through my blogs
Decimal is a base 10 number system, made up of digits 0-9. In this blog post, I will look at converting Decimal to Hexadecimal and Binary numbers.
Decimal to Binary
Helps to know the powers of 2

Converting a decimal number to binary involves repeatedly dividing the decimal number by powers of 2 while noting the remainder. You start with the largest power of 2 less than or equal to the decimal number and write '1' if it goes into the number or '0' if it doesn't. Then, subtract the result from the decimal number and continue with the remainder, repeating the process until there's no remainder left. The binary representation is the sequence of '1s' and '0s' you've written down.
There are two methods to convert a decimal number to a binary number
Subtraction method
Successive division
Subtraction method
Using the powers of 2 system, choose the highest number that will go into your decimal number.
Examples:

Start with the largest power of 2 that is less than or equal to 75, which is 64. Since 64 goes into 75, we can use it, and we write down a '1' as the first binary digit.
Now, subtract 64 from 75, which leaves us with a remainder of 11.
Next, find the largest power of 2 less than or equal to the remainder, which is 8. Since 8 goes into 11, we write down another '1' as the second binary digit.
Subtract 8 from the remainder (11 - 8 = 3).
Continue this process, finding the largest power of 2 for the remaining remainder. The next power of 2 is 2, and since 2 goes into 3, we write down '1' as the third binary digit.
Subtract 2 from the remainder (3 - 2 = 1).
Finally, for the remaining remainder (1), the largest power of 2 less than or equal to it is 1 itself. Since 1 goes into 1, we write down '1' as the fourth binary digit.
There are no more remainders left, so we stop.
So, the binary representation of the decimal number 75 is 100101.
Here are two more examples:

This next example required a larger power of 2 base, the next number to add is 256 (128 x 2)

Successive division
The successive division method for converting a decimal number to binary involves repeatedly dividing the decimal number by 2 until you reach 0.
Start by dividing the decimal number by 2.
If there is no remainder, write down a '0' as the binary digit.
If there is a remainder, write down '1' as the binary digit.
Continue this process, using the result of each division as the input for the next division.
Repeat steps 2 and 3 until you've divided all the way to 0.
For example, if you have the decimal number 75:
First division: 75 ÷ 2 = 37 with a remainder of 1, so you write down '1'.
Second division: 37 ÷ 2 = 18 with a remainder, so you write down '1'.
Third division: 18 ÷ 2 = 9 with no remainder, so you write down “0”
Fourth division: 9 ÷ 2 = 4 with a remainder of 1, so you write down '1'.
Fifth division: 4 ÷ 2 = 2 with no remainder, so you write down '0'.
Sixth division: 2 ÷ 2 = 1 with no remainder, so you write down '0'.
Seventh division: 1 ÷ 2 = 0 with a remainder of 1, so you write down '1'.
This method is read from the bottom up, meaning the final division calculated is the first digit of the binary number.
- The binary number for the above example of 75 is 1001011
MSB = Most Significant Bit
LSB = Least Significant Bit
Examples:

Decimal with a decimal point to a Binary
Divide the full number by 2, your remainder numbers make up your binary number before the decimal point.
Multiply anything after the decimal point by 2 - once the numbers after the decimal point reach 0, the numbers before your decimal point make up the binary number after the decimal point
Examples:

Decimal to Hexadecimal
Decimal = base 10 system
- 0-9
Hexadecimal = base 16 system
- 0-9, A-F
To convert a decimal number to a hexadecimal number, you can follow these steps:
Divide the Decimal Number by 16: Begin by dividing the decimal number by 16.
Keep Track of Remainders: As you perform the division, keep track of the remainders at each step. The remainder will be a digit in the hexadecimal representation.
Continue Division: Continue the division process, using the quotient obtained from the previous step as the new dividend, until the quotient becomes zero.
- a quotient is a quantity produced by the division of two numbers.
Convert Remainders to Hexadecimal Digits: At each step where you calculate a remainder, you will have a number between 0 and 15. These numbers need to be converted to their hexadecimal equivalents:
0 to 9 remain the same in hexadecimal.
10 to 15 is equivalent to 'A-F' in hexadecimal.
Arrange Hexadecimal Digits: Write down the hexadecimal digits obtained from the remainders in reverse order, starting from the last remainder you calculated.
Examples: using a calculator

The numbers are read from bottom to top, therefore the hexadecimal for 479 is 1DF.

The hexadecimal for 894 is 37E
Examples: Using long division (no calculator)
It is helpful to know the multiples of 16 for this method







