Sunday, March 8, 2020

How to Read and Write Binary Numbers

How to Read and Write Binary Numbers When you learn most types of computer programming, you touch upon the subject of binary numbers. The binary number system plays an important role in how information is stored on computers because computers only understand numbers - specifically, base 2 numbers. The binary number system is a base 2 system that uses only the numerals 0 and 1 to represent off and on in a computers electrical system. The two binary digits 0 and 1 are used in combination to communicate text and  computer processor instructions. Although the concept of binary numbers is simple once explained, reading and writing binary is not clear at first. To understand binary numbers, which use a base 2 system, first look at the more familiar system of base 10 numbers. Writing in Base 10 Take the three-digit number 345, for example. The farthest right number, 5, represents the 1s column, and there are 5 ones. The next number from the right, the 4, represents the 10s column. Interpret the number 4 in the 10s column as 40. The third column, which contains the 3, represents the 100s column. Many people know base 10 through education and years of exposure to numbers. The Base 2 System Binary works in a similar way. Each column represents a value. When one column is filled, move to the next column. In a base 10 system, each column  needs to reach 10 before moving to the next column. Any column can have a value of 0 through 9, but once the count goes beyond that, add a column. In base 2 or binary, each column can contain only  0 or 1 before moving to the next column. In base 2, each column represents a value that is double the previous value. The values of positions, starting on the right, are 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, and so on. The number one is represented as 1 in both base ten and binary, so lets move on to the number two. In base ten, it is represented with a 2. However,  in binary, there can be only a 0 or a 1 before moving on to the next column. As a result, the number 2 is written as 10 in binary. It requires a 1 in the 2s column and 0 in the 1s column. Take a look at the number three. Obviously, in base 10 it is written as 3. In base two, it is written as 11, indicating a 1 in the 2s column and a 1 in the 1s column. This becomes 21 3. Binary Number Column Values When you know how binary works, reading it is simply a matter of doing some simple math. For example: 1001:  Since we know the value each of these slots represents, then we know this number represents 8 0 0 1. In base 10, this would be the number 9. 11011:  Calculate what this is in base 10 by adding the value of each position. In this case, this becomes 16 8 0 2 1. This is the number 27 in base 10. Numbers at Work in a Computer So, what does all this mean to the computer? The computer  interprets  combinations of binary numbers as text or instructions. For example, each lowercase and uppercase letter of the alphabet is assigned a different binary code. Each is also assigned a decimal representation of that code, called an  ASCII code. For example, the lowercase a is assigned the binary number 01100001. It is also represented by the ASCII code 097. If you do the math on the binary number, youll see it equals 97 in base 10.