Decimal to binary

int data_holder = 33;

As shown in the above statement, when we assign a decimal value to a variable, first the value is converted to binary from decimal value, and later it will be stored in computer memory space. Let’s see how to do that.

Consider the decimal value is 33. Now to get the binary value from this decimal value divide this value with ‘2’ repeatedly until you get ‘1’.

100001After dividing it, note down the remainder from bottom to top. Then the binary value looks like

At each step, note down the remainder that you are getting. For more info see the below picture.

Decimal to Octal:

Steps to follow:

  1. Decimal to binary (Refer to above section)
  2. Binary to octal (Refer to this article)

Example:

Decimal: 33
Binary: 100001
Octal: 41

Decimal to Hex:

Steps to follow:

  1. Decimal to binary (Refer to above section)
  2. Binary to Hexa (Refer to this article)

Example:

Decimal: 33
Binary: 100001
Hexa: 21

Categorized in:

Tagged in: