Category:Storing numbers

From Higher Computing Science
Jump to: navigation, search

This article is unfinished. Please consider joining and adding to this article. Read about Page layout beforehand.

Key points

  • Binary is the name given to the base 2 number system. Binary numbers are represented with two values, 0 and 1.
  • Computers store numbers as binary code.
  • Converting between decimal and binary can be carried out by grouping the number into values that represent each binary column: 128, 64, 32, 16, 8, 4, 2, 1
  • To convert a decimal number to binary, start with the highest possible number that is smaller (or equal to) the decimal number, and place a 1 under the column needed. Repeat the process with the remainder of the number. Place a 0 in any unused column.
  • To convert a binary number to decimal, add together the values of each column.
  • Two’s complement binary is used when numbers must be positive or negative
  • Two’s complement binary uses the highest value column to represent a negative number instead of a positive number (for example, an 8 bit two’s complement number stores the number -128 in the highest bit)
  • To calculate the two’s complement for a negative number, flip the bits of the binary for the positive version of the number, and add one. (e.g 65 is 01000001 so to get -65 you need to flip the bits to 10111110 and add one, giving 10111111). This can be double checked by adding the columns: -128 + 32 + 16 + 8 + 4 + 2 + 1

Information

Videos

Two's complement


Further information

Test yourself

Teaching resources

This article is unfinished. Please consider joining and adding to this article. Read about Page layout beforehand.

Key points

  • A real number is a simple data type stored as a floating point number – a number split into two parts
  • A real number is a number with a fractional part (or decimal place).
  • A real number is stored in parts called the mantissa and exponent. This kind of number is called a floating point number.
  • The mantissa is a number used to store the precision of the number. The number of bits reserved for the mantissa determines its precision.
  • The exponent is a number used to store the range of a number. The number of bits reserved for the exponent determines its range.
  • Floating point numbers can also used an extra bit called a signed bit to indicate whether a number is positive or negative

Information

Computers store whole numbers using binary. This represents numbers as a set of 1s and 0s. A decimal point cannot be represented by a binary number.

Using fractional binary

It is possible to represent fractions of a whole number using binary, by utilising columns as follows

Fractionalbinary.png

This number is 9.75 (8+1+0.5+0.25).

Fractional binary is useful, but cannot store numbers larger than the number of bits allocated, for example, if 16 bits were used to store the fractional binary numbers, 8 bits would store numbers above 0 (up to 255) and 1/2, 1/4, 1/8, 1/16, 1/32, 1/64, 1/128, 1/256 could be stored with the other 8 bits.

To store numbers outside of the range of binary storage, a new approach is needed.

Floating point representation

A floating point number is a number represented in two parts. The detail of the number (all the digits) are represented in one part, called the mantissa, and the range of the number (how many zeros follow or precede the number) are represented in another part, called the exponent.

Floatingpoint.png

If the exponent is a negative number, this will make the floating point number a decimal.

How is a floating point number stored?

A floating point number is stored using a number of bits for the mantissa, and a number of bits for the exponent. There is also usually a bit stored to indicate whether the value is positive or negative.

618px-IEEE 754 Single Floating Point Format.svg.png

  • If the number of bits for the mantissa is increased, the detail of the number will improve
  • If the number of bits for the mantissa is reduced, the detail of the number will be reduced
  • If the number of bits for the exponent is increased, the range of the number will improve
  • If the number of bits for the exponent is reduced, the range of the number will be reduced

Videos

Further information

Test yourself

Teaching resources

Subcategories

This category has only the following subcategory.

Pages in category "Storing numbers"

The following 2 pages are in this category, out of 2 total.