What Is Binary Code and How Does It Work?

Learn about the binary number system

First invented by Gottfried Leibniz in the 17th century, the binary number system became widely used once computers required a way to represent numbers using mechanical switches.

What Is Binary Code?

Binary is a base-2 number system representing numbers using a pattern of ones and zeroes.

Early computer systems had mechanical switches that turned on to represent 1, and turned off to represent 0. By using switches in series, computers could represent numbers using binary code. Modern computers still use binary code in the form of digital ones and zeroes inside the CPU and RAM.

A digital one or zero is simply an electrical signal that's either turned on or turned off inside of a hardware device like a CPU, which can hold and calculate many millions of binary numbers.

Binary numbers consist of a series of eight "bits," which are known as a "byte." A bit is a single one or zero that makes up the 8 bit binary number. Using ASCII codes, binary numbers can also be translated into text characters for storing information in computer memory.

Image of binary code


How Binary Numbers Work

Converting a binary number into a decimal number is very simple when you consider that computers use a base 2 binary system. The placement of each binary digit determines its decimal value. For an 8-bit binary number, the values are calculated as follows:

  • Bit 1: 2 to the power of 0 = 1
  • Bit 2: 2 to the power of 1 = 2
  • Bit 3: 2 to the power of 2 = 4
  • Bit 4: 2 to the power of 3 = 8
  • Bit 5: 2 to the power of 4 = 16
  • Bit 6: 2 to the power of 5 = 32
  • Bit 7: 2 to the power of 6 = 64
  • Bit 8: 2 to the power of 7 = 128

By adding together individual values where the bit has a one, you can represent any decimal number from 0 to 255. Much larger numbers can be represented by adding more bits to the system.

When computers had 16-bit operating systems, the largest individual number the CPU could calculate was 65,535. 32-bit operating systems could work with individual decimal numbers as large as 2,147,483,647. Modern computer systems with 64-bit architecture have the ability to work with decimal numbers that are impressively large, up to 9,223,372,036,854,775,807!

Representing Information With ASCII

Now that you understand how a computer can use the binary number system to work with decimal numbers, you may wonder how computers use it to store text information.

This is accomplished thanks to something called ASCII code.

The ASCII table consists of 128 text or special characters that each have an associated decimal value. All ASCII-capable applications (like word processors) can read or store text information to and from computer memory.

Some examples of binary numbers converted to ASCII text include:

  • 11011 = 27, which is the ESC key in ASCII
  • 110000 = 48, which is 0 in ASCII
  • 1000001 = 65, which is A in ASCII
  • 1111111 = 127, which is the DEL key in ASCII

While base 2 binary code is used by computers for text information, other forms of binary math are used for other data types. For example, base64 is used for transferring and storing media like images or video.

Binary Code and Storing Information

All of the documents you write, web pages you view, and even the video games you play are all made possible thanks to the binary number system.

Binary code allows computers to manipulate and store all types of information to and from computer memory. Everything computerized, even the computers inside your car or your mobile phone, make use of the binary number system for everything you use it for.

Was this page helpful?