Enter a number in binary, octal, decimal or hexadecimal and this converter gives its value in all four number systems. It also shows the working the way it is done in the Class 11 Computer Science chapter Encoding Schemes and Number System: repeated division for the whole-number part, repeated multiplication for the fractional part, place values for converting to decimal, and grouping of bits for octal and hexadecimal.
The four number systems
A number system is a way of writing numbers using a fixed set of digits. The number of digits it uses is called its base (or radix). The base is written as a subscript, so (101)2 and (101)10 are different numbers.
- Binary (base 2): digits 0 and 1. Computers store all data in binary.
- Octal (base 8): digits 0 to 7. One octal digit stands for 3 bits.
- Decimal (base 10): digits 0 to 9, the system we use every day.
- Hexadecimal (base 16): digits 0 to 9 and A to F, where A = 10, B = 11, C = 12, D = 13, E = 14, F = 15. One hex digit stands for 4 bits, so it is a short way to write long binary numbers, for example in colour codes and memory addresses.
How the conversions work
Any base to decimal
Multiply each digit by its place value and add. The place value is the base raised to the position of the digit: 0 just left of the point, then 1, 2, 3 going left, and −1, −2 going right.
(d2d1d0.d−1)b = d2 × b2 + d1 × b1 + d0 × b0 + d−1 × b−1
Decimal to any base
Whole-number part: divide by the new base again and again until the quotient is 0. The remainders, read from the last one to the first (bottom to top), give the answer.
Fractional part: multiply the fraction by the new base again and again. Each time, the whole-number part of the result is the next digit; carry only the fractional part forward. Read the digits from top to bottom. Stop when the fraction becomes 0. Some fractions, such as 0.1, never become 0 in binary, so the answer is cut off after a few places.
Binary to octal or hexadecimal, and back
Since 8 = 23 and 16 = 24, no decimal step is needed. Starting at the point, split the binary number into groups of 3 bits for octal or 4 bits for hexadecimal (go left for the whole part and right for the fraction, adding zeros at the ends if needed), then write each group as one digit. To go back, write each octal digit as 3 bits or each hex digit as 4 bits. To change octal to hexadecimal, go through binary.
Worked example
Question: Convert (25.625)10 into binary, octal and hexadecimal.
Whole part 25 to binary: 25 ÷ 2 = 12 remainder 1; 12 ÷ 2 = 6 r 0; 6 ÷ 2 = 3 r 0; 3 ÷ 2 = 1 r 1; 1 ÷ 2 = 0 r 1. Reading the remainders from the bottom: 11001.
Fraction 0.625 to binary: 0.625 × 2 = 1.25 (digit 1); 0.25 × 2 = 0.5 (digit 0); 0.5 × 2 = 1.0 (digit 1). The fraction is now 0. Reading from the top: .101.
So (25.625)10 = (11001.101)2.
To octal (groups of 3): 011 001 . 101 → 3 1 . 5, so (31.5)8.
To hexadecimal (groups of 4): 0001 1001 . 1010 → 1 9 . A, so (19.A)16.
Check: (11001.101)2 = 16 + 8 + 1 + 0.5 + 0.125 = 25.625. Also (19.A)16 = 1 × 16 + 9 + 10 ÷ 16 = 25.625.
Common mistakes
- Reading the remainders from top to bottom. For the whole-number part they are read from the bottom up; for the fractional part the digits are read from the top down.
- Grouping bits from the left end of the number. Groups must start at the point: leftwards for the whole part and rightwards for the fraction, padding with zeros at the outer ends.
- Writing 10, 11, 12 as two digits in hexadecimal. A remainder of 10 to 15 is a single hex digit A to F.
- Using a digit that does not belong to the base, such as 8 in octal or 2 in binary.
- Giving the place value b1 to the last digit of the whole-number part. The digit just left of the point always has place value b0 = 1.
Practise with
- NCERT Book Class 11 Computer Science Encoding Schemes and Number System
- Samacheer Kalvi Class 11 Computer Science Solutions Chapter 2 Number Systems
- CBSE Class 11 Computer Science Revision Notes
- CBSE Class 9 Computer Science Number System MCQs
The converter works with positive numbers whose whole-number part is below 264 and with up to 10 digits after the point. Fractions that do not end are shown to 12 places.