DEV Community

Ani
Ani

Posted on

Binary system and subtraction

Number systems are ways of representing numbers by writing some symbols and digits in a consistent order. There are various systems to represent numbers and they’re all interconnected, that is, we can convert from one system to another. There are a lot of systems and each is used in its own way. Here are some of the most commonly used ones:

Decimal System (base 10)- The system we are all familiar with and use in our everyday life. “Why decimal?” you may ask. The answer is very simple! The prefix ‘deci’ means one-tenth, for instance, there are 10 DECImeters on 1 meter. Another example, there are 10 years in a DECade, and so on. The decimal system is also called “base 10” as it has 10 digits: 0-9.

Binary system (base 2)- The language of computers. The computer’s main memory is made of transistors or so-called switches that switch from 0 to 1 with electrical voltage, allowing the computer to process, store information, and conduct other operations. This system is called binary as the prefix “bi” means two, like bicycle, and it contains two digits, 0 and 1.

Octal system (base 8)- Although this system has been replaced with the hexadecimal system, it was used in the early days of computing for addressing and data storage. This system has not entirely disappeared as it is sometimes used in some programming environments. The prefix octa means eight, take for example an octopus, and it contains eight digits, from 0 to 7.

Hexadecimal system (base 16)- After replacing the octal system, this system is widely used for representing memory addresses, colors, Unicode character codes, and so on. The name hexadecimal comes from prefixes “hexa”, which means six, and “deci”. Unlike the previous systems, this system also uses letters, from A to F, along with digits from base 10.

Let’s move on to operations with binary numbers. Subtraction and division, to be exact.
Subtraction
In one way, we can convert the binary number to a decimal, do the subtraction then convert it back to a binary number. But let’s try it with binary numbers.

subtraction example

  • we know that 1-0=0
  • we need to borrow 1 from 1, which leaves us with two 1s on the next column
  • borrow one of the ones for the next subtraction, again leaving us with two 1s in the next column
  • 1-1=0
  • write down the other 1s
  • we get 111

We can check it by converting binary numbers into decimals:
(1):2^0*1=1
(0):2^1*0=0
(0):2^2*0=0
(1):2^3*1=8
8+0+0+1=9
1001=9

(0):2^0*0=0
(1):2^1*1=2
0+2=2
10=2

9-2=7

convert back to binary
7|1
3|1
1|1

7=111

Hence, our subtraction is right.

Thank you for your time.

Top comments (0)