Binary Number System
Published by
sanya sanya
What is it and how is it different from decimal?
The binary number system is a numeral system that uses only two digits, 0 and 1, to represent numbers. It is also known as the base-2 system because it operates with base 2.
In contrast, the decimal number system, which is the most common numeral system, uses ten digits (0-9) and operates with base 10.
Conversion from one to another
In the binary system, each digit represents a power of 2, starting from the rightmost digit. The rightmost digit represents 2^0(1), the next digit represents 2^1(2), then 2^2(4) and so on. By combining these digits any number can be represented in binary.
To convert decimal to binary, divide the number by 2 repeatedly until quotient becomes 0. At each division, keep track of remainders which will form the binary representation when read in reverse order.
Example to convert 42 to binary:
- Divide 42 by 2:
- Quotient: 21
- Remainder: 0 (LSB)
- Divide 21 by 2:
- Quotient: 10
- Remainder: 1
- Divide 10 by 2:
- Quotient: 5
- Remainder: 0
- Divide 5 by 2:
- Quotient: 2
- Remainder: 1
- Divide 2 by 2:
- Quotient: 1
- Remainder: 0
- Divide 1 by 2:
- Quotient: 0
- Remainder: 1 (MSB)
The remainders are read in reverse order giving binary representation as 101010.
To convert a binary number to decimal, you multiply each binary digit by the corresponding power of 2 and sum the results.
Example to convert 101010 in decimal:
1 * 2^5 + 0 * 2^4 + 1 * 2^3 + 0 * 2^2 + 1 * 2^1 + 0 * 2^0 = 32 + 0 + 8 + 0 + 2 + 0 = 42
Hence 101010 is 42 in decimal.
Library
WEB DEVELOPMENT
FAANG QUESTIONS