# Number System and Base Conversions

Electronic and Digital systems may use a variety of different number systems, (e.g. Decimal, Hexadecimal, Octal, Binary).

A number N in base or radix b can be written as:

(N)_{b} = d_{n-1} d_{n-2} — — — — d_{1} d_{0} . d_{-1} d_{-2} — — — — d_{-m}

In the above, d_{n-1} to d_{0} is integer part, then follows a radix point, and then d_{-1} to d_{-m} is fractional part.

d_{n-1} = Most significant bit (MSB)

d_{-m} = Least significant bit (LSB)

**How to convert a number from one base to another?**

Follow the example illustrations:

## 1. Decimal to Binary

(10.25)_{10}

**Note: **Keep multiplying the fractional part with 2 until decimal part 0.00 is obtained.

(0.25)_{10} = (0.01)_{2}

**Answer:** (10.25)_{10} = (1010.01)_{2}

## 2. Binary to Decimal

(1010.01)_{2}

1×2^{3} + 0x2^{2} + 1×2^{1}+ 0x2^{0} + 0x2 ^{-1} + 1×2 ^{-2} = 8+0+2+0+0+0.25 = 10.25

(1010.01)_{2} = (10.25)_{10}

## 3. Decimal to Octal

(10.25)_{10}

(10)_{10} = (12)_{8}

Fractional part:

0.25 x 8 = 2.00

**Note:** Keep multiplying the fractional part with 8 until decimal part .00 is obtained.

(.25)_{10} = (.2)_{8}

**Answer:** (10.25)_{10} = (12.2)_{8}

## 4. Octal to Decimal

(12.2)_{8}

1 x 8^{1} + 2 x 8^{0} +2 x 8^{-1} = 8+2+0.25 = 10.25

(12.2)_{8} = (10.25)_{10}

## 5. Hexadecimal and Binary

To convert from Hexadecimal to Binary, write the 4-bit binary equivalent of hexadecimal.

(3A)_{16} = (00111010)_{2}

To convert from Binary to Hexadecimal, group the bits in groups of 4 and write the hex for the 4-bit binary. Add 0's to adjust the groups.

1111011011

(001111011011 )_{2} = (3DB)_{16}

This article is contributed by **Kriti Kushwaha**.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.

## Recommended Posts:

- Conversion of Binary number to Base 4 system
- Ternary number system or Base 3 numbers
- Given a number N in decimal base, find number of its digits in any base (base b)
- Given a number N in decimal base, find the sum of digits in any base B
- Find the Nth digit from right in base B of the given number in Decimal base
- C++ program to find all numbers less than n, which are palindromic in base 10 and base 2.
- Add two integers of different base and represent sum in smaller base of the two
- Different ways for Integer to String Conversions In Java
- Convert the number from International system to Indian system
- Convert the number from Indian system to International system
- Complement of a number with any base b
- Check if a number is in given base or not
- Pandigital number in a given base
- Check if a N base number is Even or Odd
- Largest value of x such that ax
^{x}is N-digit number of base b - Check if a number N starts with 1 in b-base
- Largest N digit number in Base B
- Find most significant bit of a number X in base Y
- Check whether a number has consecutive 0's in the given base or not
- Convert a number into negative base representation