Decimal and binary number systems are known to have a different base that represents the total number of digits that are used in that number system. The decimal number system uses any of the 10 digits (0 to 9) to represent a number. So it has a base of 10. The binary number system represents a number consisting of only two digits, 0 and 1. Every digit of a binary number is either 0 or 1. Therefore this number system is said to have a base of 2. A decimal number can be represented as an equivalent binary number. When a decimal number is converted to an equivalent binary number, the base of the number changes from 10 to 2. The binary system finds its wide application in electronics and computers, so programmers should understand how to convert from decimal to binary.
Table of Contents
Let’s understand this with an example:
- How to convert 32 into binary form?
Solution:
- 32/16 = 2 R = 0
- 16/2 = 8 R = 0
- 8/2 = 4 R= 0
- 4/2 = 2 R= 0
- 2/2 = 1 R= 0
- ½ = 0 R = 1
If you read this in reverse order, you will get a binary form of this number i. e 100000
The commonly used method for converting a decimal number into a binary number is by performing short division by 2 with the remainder (for integer part) and performing short multiplication by 2 with the result (for the decimal part).
To convert a decimal number to a binary number, the integer part of a given decimal number is divided by 2 repeatedly because the binary number system has a base value of two. The remainder in each step is noted down till 0 is obtained as the final quotient. These reminders are then written in reverse order to obtain a binary number of the integer part of the given decimal number.
For example, the decimal number 18 can be represented by the binary number 10010.
For conversion of the decimal part of a number to an equivalent binary value, it is to be multiplied by 2. Note down the value of the integer part of the product, which will be either 0 or 1. Continue multiplying the remaining decimal part and note the integer part of the result of every step till we get 0. Then write the noted integer values serially, which will be the equivalent binary number of the given decimal part.
What are Decimals?
In mathematics, decimals are another way of representing fractions. A decimal number consists of a whole part and a decimal part separated by a decimal point. The number of digits in the decimal part of a decimal number denotes the decimal places. A decimal number system is a convenient way of representing fractions and is one of the oldest known number systems.
For example, 12.345 is a decimal number in which 12 is the whole number and 345 is the decimal part. It has three decimal places. Again, 0.89 is also a decimal number in which the whole part is zero and the decimal part is 89. This number has two decimal places.
In the above examples, 12.345 can be considered as a decimal number representing a mixed fraction which is a combination of a whole part denoted by 12 and a proper fraction denoted by 0.345. The decimal number 0.67 represents a proper fraction with no whole part in it.
In decimals, as we start from left to right after the decimal point, the place value of digits will be divided by 10, which means the decimal place value shows the tenth, hundredth, etc. Thus, the decimal form 0.7 means 7/10, and the decimal from 0.13 refers to 13/100. You can practice this concept on cuemath.com
Types of Decimal Numbers
Decimal Numbers can be of different kinds. These are as follows:
Recurring Decimal Numbers (Repeating decimal digits)
Example: 3.241241
Non-Recurring Decimal Numbers (Non Repeating decimal digits)
Example: 2.1538
Like Decimal Numbers (Decimals having the same decimal places)
Example: 5.02. 7.81, 13.75 are like decimals as all of them have two decimal places.
Unlike Decimal Numbers (Decimals having different decimal places)
Example: 1.5, 6.08, 25.137 are unlike decimals having different decimal places.