Binary may refer to any of the following:
1. Binary is a base-2 number system invented by Gottfried Leibniz that's made up of only two numbers or digits: 0 (zero) and 1 (one). This numbering system is the basis for all binary code, which writes digital data such as the computer processor instructions used with your devices every day.
How does binary work?
The 0s and 1s in binary represent OFF or ON, respectively. In a transistor, a "0" represents no flow of electricity, and a "1" represents electricity is allowed to flow. This way, numbers are physically represented inside the computing device, permitting calculations. This concept is further explained in our section on how to read binary numbers.
Why computers use binary
Binary is still the primary language for computers and is used with electronics and computer hardware for the following reasons.
- It is a simple and elegant design.
- Binary's 0 and 1 method quickly detects an electrical signal's off (false) or on (true) state.
- Having only two states placed far apart in an electrical signal makes it less susceptible to electrical interference.
- The positive and negative poles of magnetic media are quickly translated to binary.
- Binary is the most efficient way to control logic circuits.
- The switches that the modern computer use today can only reliably hold two states (on and off).
Quantum computers use a qubit, which can be 0, 1, or both at the same time.
How to read binary numbers
Because the numbering system only supports a "0" and a "1," other numbers like "2" must be represented in binary by turning on and off each bit. With binary, the first bit place equals "1," and the second is equal to "2." So, to get the value of "2," the first bit would be turned off, and the second bit would be turned on, for a binary value of "10." With binary, it's important to realize you read right to the left. If you wanted the binary value to equal "3," the first and second bits would be turned on, for a binary value of "11" (1+2=3).
Counting on a computer often starts at "0" instead of "1."
To get a number larger than "3," additional bits must be added. As bits are added, their value is double that of the previous bit. So, when adding the third bit, we double the previous value of "2" to get "4." Each bit column represents the number two raised to an exponent (base 2), with that exponent's value increasing by one as you move through each of the eight positions. So, to represent "4" in binary is "100" (0+0+4=4). If all three bits were on (111), this equals "7" (1+2+4=7).
If we need a number larger than "7," an extra bit must be added. So, doubling "4" (the previous largest bit), our next bit would become "8." So, to represent "8" in binary is "1000." If we had the binary number "1100," we'd have "12" (0+0+4+8=12) since only two of the four bits are turned on.
With 4-bit, you reach the next measurement after a bit called a nibble.
To represent a character or symbol, we start at a byte, which is 8-bit. The following chart illustrates the binary number 01101000. To get the total of this example, read the chart from right to left and add each column's value with a "1" to the previous column. In the following table, this would be 0+0+0+8+0+32+64+0, which equals 104. The bits with 0 are not counted because they're "turned off."
The following example is 11111111 in binary, with a maximum 8-bit value of 255. Again, reading right to left, we have 1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 = 255.
Because counting starts at "0" instead of "1," all the bits turned on equals 255, but if you count 0, its total is 256.
When you have eight bits, it's equal to one byte. If you take the binary code from the first example (01101000), which totaled "104," and put it into ASCII, it produces a lowercase "h." To spell "hi," add the binary for the letter "i," which is 01101001 (105) in ASCII. Putting these two codes together, we have 0110100001101001 or 104 and 105, representing "hi." Further information on the binary-to-ASCII conversion is found on the following link.
Dealing with numbers larger than 255 in binary
To deal with numbers larger than 255, the number of bits used is doubled. For example, if you double the 8-bit to 16-bit (216), you have 65,536 number combinations. Increasing to 32-bit (232) gives you 4,294,967,296 number combinations. Increasing to 64-bit (264) gives you 18,446,744,073,709,551,616.
When storing (mapping) an 8-bit binary number like "01101000" (104 in decimal) as 16-bit, it becomes "00000000 01101000," and as 32-bit, it becomes "00000000 00000000 00000000 01101000." If you were dealing with a larger number than 255, such as "12,345," it's stored as "00110000 00111001" (8192 + 4096 + 32 + 16 + 8 + 1) in 16-bit.
See our 16-bit page for a table on converting up to 65,535.
Does binary use more storage than decimal?
The length of a decimal number (e.g., 234) is smaller than the length of a binary number that equals 234 (11101010). So, many incorrectly assume it would take less storage to store "234" instead of "11101010."
However, the "234" you see on the screen is only shown to make it easier for you to read. When the computer stores and transfers any data, it's all binary. Increasing a number's base usually makes its visual length smaller but doesn't change how much space it occupies on a drive.
How to add in binary
Adding in binary works a lot like adding in decimal. For example, if we had the binary 01101011 (107) and wanted to add 10000111 (135), we'd follow the following steps.
Starting from the right side, we'd add 1+1 to get "2." Because there's no number two in binary, we'd use the binary value "10" and carry the "1" to the next column.
In the next column, we'd add the "1" we carried over to the next column and add 1+1+1 to get "3." There is no number "3" in binary, so we use "11" (3 in binary) and put 1 and carry the 1 to the next column.
Next, we'd add the "1" again that was carried over and add 1+0+1 to get "10" (2 in binary).
We repeat this process for all eight digits to get the result 11110010 (242).
What are a left shift and right shift?
A left shift is when each bit in the binary number is shifted (moved) to the left to double the binary value or multiplied by two. For example, the binary number "00000011" equals three, and when left-shifted, it becomes "00000110," which equals six. As another example, the binary number "00111110" equals 62, and shifting the bits to the left makes "01111100" or 124.
A right shift is like a left shift, except the bits are shifted to the right to divide the number by two. For example, the binary number "00001010" equals ten, and when right shifted, it becomes "00000101" or five.
What is the "0b" prefix?
To help prevent confusion, when writing a binary number, it may have a "0b" (zero and b) prefix. For example, 0b0100 represents "0100" in binary. By using this prefix, the reader knows this is not "100" in decimal.
The image is an example of some binary humor (joke) via a famous saying on many geek t-shirts. Those who can read binary realize this quote says, "There are only two types of people in the world: Those who understand binary and those who don't." In the binary system, 10 is two, not the decimal number ten.
Convert text into binary
The following tool converts any text into binary.
2. In an FTP session, binary is a command that switches the file transfer mode to binary. For information about binary and other FTP commands, see: How to use FTP from a command line.
3. When used as a noun, the term "binary" may refer to an executable file. For example, "locate the binary named program.exe, and double-click it."
Base, BCD, .BIN, Binary file, Bit, Decimal, Hexadecimal, Least significant bit, Machine language, Most significant bit, Native language, Negation, Nibble, Octal, OFF, ON, Qubit, Software terms, Ternary, Two's complement