Representing numbers

One important function of the CPU is to perform operations on numbers such as adding values together. In programs, numbers are defined as integers or floating point numbers.

Integers are whole numbers and floating point numbers are numbers with decimal points.

Computers use a fixed number of bits to represent integers. The most common bit-lengths for integers are 8-bit, 16-bit, 32-bit and 64-bit. Programmers choose an appropriate number of bits to represent integers in a program. If you use an 8-bit integer variable in a program, the largest value it can take will be 255.

In binary, it can be more difficult to represent numbers that contain a decimal point. It can also be difficult to represent extremely small or large numbers. Pi is a difficult number for computers to represent as it has an infinite number of decimal places.

Did you know?

Every device on the internet has a unique IP address. The version most used in recent years is version four, also known as IPv4, which uses a 32-bit number system. A complete IP address is normally viewed as a number, such as a series of whole numbers - for example 192.168.0.12. Each number can be between 0 and 255, which allows just over 4 billion unique addresses.

IPv6 is now coming into use. IPv6 uses 16 bits for each section of the address, creating a 128-bit address. This allows potentially almost 80 octillion unique IP addresses.