DEV Community

Cover image for Binary
Mkrtich Arakelyan
Mkrtich Arakelyan

Posted on

Binary

Hello, my name is Mkrtich.

Today, I will write about what binary numbers are, how to convert numbers into other bases, and about operations using binary numbers.
First of all, binary is the fundamental in computing. There are only two symbols in binary, 1 and 0, so we can say that binary is just a base-2 numbering system. Each number in binary represents a bit, and 8 bits together form a bite.
Next, we can discuss converting a decimal number into another base.
Divide the decimal number by the desired base.
Write down the remainder.
Write down the integer quotient.
Repeat steps 1-3 with the integer quotient until it becomes 0.
The remainder, read in reverse order, form the decimal number representation in the desired base.
For example, to convert 27 into binary:

27 ÷ 2 = 13 with a remainder of 1. Write down 1.
13 ÷ 2 = 6 with a remainder of 1. Write down 1.
6 ÷ 2 = 3 with a remainder of 0. Write down 0.
3 ÷ 2 = 1 with a remainder of 1. Write down 1.
1 ÷ 2 = 0 with a remainder of 1. Write down 1.
Reading the remainder from bottom to top gives you the binary representation:

27 in binary is 11011.

Now, let's discuss how to convert a binary number into a decimal number.
Starting from the rightmost digit (the least significant bit) and moving to the left, assign a positional value to each digit, starting with 2^0 for the rightmost digit and increasing the exponent by 1 for each digit to the left.

So, for the binary number 11011:

Start from the rightmost digit: 1 * 2^0 = 1.
Move to the next digit to the left: 1 * 2^1 = 2.
Continue to the next digit: 0 * 2^2 = 0.
Move to the next number: 1 * 2^3 = 8.
Finally, the leftmost digit is 1 * 2^4 = 16.
Now, add up all these values:

1 + 2 + 0 + 8 + 16 = 27

So, the binary number 11011 is equal to the decimal number 27.

Now, let us talk about operations using binary. All operations in binary are done in the same way as they are done with decimal numbers. Here are some examples

1) Addition
Add corresponding bits from right to left, carrying over any 1 that exceeds 1 into the next column. Example:

Image description

2) Binary Subtraction:

Borrow 1 from the next higher column if necessary. Example:

Image description
Explanation: When subtracting in binary, if you can't directly subtract the lower digit from the higher one, borrow 1 from the next higher column.

3) Binary Multiplication:

Multiply each digit in one number by each digit in the other and shift accordingly. Example:

Image description
Explanation: Multiply each digit in the first number by each digit in the second number and shift the results appropriately.

4) Binary Division:

Divide the largest possible portion of the dividend by the divisor and record the quotient. Example:

Image description

Explanation: Divide as you would in decimal division, finding the largest portion of the dividend that can be divided by the divisor.
That's all for today.

Top comments (0)