From Higher Computing Science
This article is unfinished. Please consider joining and adding to this article. Read about Page layout beforehand.
- 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