top of page

Exam Board:
OCR A-Level

4.1 - Data Types

Specification:
Computer Science H446

Watch on YouTube:
Data types
Denary & binary
Sign and magntiude
Two's complement
Binary addition
Binary subtraction
Hexadecimal & binary
Hexadecimal & denary


Floating point
Floating point normalisation
Floating point addition
Floating point subtraction
Binary shifts
Masks (AND, OR, XOR)
Character sets

This is a mathematical topic that requires conversion between the binary, denary (decimal) and hexadecimal number systems. Representing positive and negative binary values is included, as well as adding and subtracting binary numbers and using normalised floating point to represent decimal numbers

Data Types

Data types are needed so that the computer knows how to store, process and interpret data correctly. They help ensure that only valid operations are performed on data. For example, you can add two numbers, but not a number and a word. Common data types:

  • Integer: A whole number, e.g. 7 or -12.

  • Real: A decimal number, e.g. 3.14 or -0.5.

  • Boolean: A data type with only two possible values - True or False.

  • Character: A single letter, digit or symbol, e.g. ‘k’, ‘7’, or ‘?’.

  • String: A sequence of characters treated as text, e.g. “CSNewbs”.

 

Converting from one data type to another is called casting, e.g. age = str(age) would convert the variable age to a string in Python.

noun-text-5970431e.png

Binary

Binary is a base-2 number system with all values comprised only of 0 and 1, e.g. 01011001. Denary (also called decimal) is the base-10 number system you grew up learning, with 10 possible values between 0 and 9, e.g. 453.

Computers use binary because they are built from electronic components (transistors) that have two states (on and off), which are easily represented by 1s and 0s. All data processed and stored by the computer (e.g. numbers, text, images and sounds) are represented in binary.

​To convert an 8-bit binary value to denary, write 128 - 64 - 32 - 16 - 8 - 4 - 2 - 1 above the binary and add together the values with a 1 underneath. For example, 10101101 is 173 (128 + 32 + 8 + 4 + 1).

noun-binary-6815170e.png

Storing Negative Numbers

-183

Sign and Magnitude and Two’s Complement are two methods of representing negative numbers in binary.

  • In Sign and Magnitude, the most significant bit (MSB) represents the sign - 0 for positive and 1 for negative - while the remaining bits store the number’s magnitude (value). For example, in 8-bit form, 0101 0010 is +82 and 1101 0010 is -82. However, this method has two representations of zero (+0 and -0), which can cause problems and may give incorrect results if used to add or subtract.

  • In Two’s Complement, negative numbers are represented by inverting all bits of the positive value and adding 1 to the result. This method has only one zero and makes binary addition and subtraction simpler.

Binary Addition & Subtraction

noun-more-or-less-55353.png

Binary addition works from right to left but only uses the digits 0 and 1. The key rules are:

  • 0 + 0 = 0

  • 0 + 1 = 1

  • 1 + 0 = 1

  • 1 + 1 = 10 (write down 0 and carry 1 to the next left column).

  • 1 + 1 = 1 = 11 (write down 1 and carry 1 to the next left column).

If the final addition produces an extra carry bit, it may indicate an overflow error, if the result is too large to fit in the available bits.

Binary subtraction can be done using borrowing, similar to denary subtraction, or more commonly by using two’s complement. In two’s complement subtraction, you add the negative version of one number (found by inverting the bits and adding 1) to the other to perform subtraction using binary addition rules.

Hexadecimal

9E8A

Hexadecimal is a base-16 number system using the digits 0 to 9 and the letters A to F, where A = 10 and F = 15 in denary. It’s often used in computing because it provides a shorter, more readable way to represent long binary values. For example, two hex digits represent eight binary bits, making conversions quick and efficient.

To convert from binary to hexadecimal, split the binary number into groups of four bits (from right to left) and convert each group into its hex equivalent. Example: 1101 01101101 (14 → D) and 0110 (6) → D6.

To convert hexadecimal to binary, replace each hex digit with its 4-bit binary equivalent. Example: 2F0010 (2) and 1111 (15 → F) → 0010 1111.

The easiest method to convert between denary and hexadecimal is to convert the value to binary first. Example: 26 0001 10101A.

Floating Point

noun-increase-decimal-7721194.png

Floating point is a way of representing real (decimal) numbers in binary using a mantissa and an exponent. It allows computers to store a wide range of values efficiently, including very small and very large numbers.

Floating point normalisation means adjusting the number so that the mantissa begins with a 01 (if it is positive) or 10 (if it is negative). This ensures the representation is unique and uses all available bits in the mantissa for precision.

 

To add or subtract floating point numbers, the exponents must first be made equal by shifting the mantissa of the smaller number. Once aligned, the mantissas are added or subtracted, and the result is then normalised again to maintain the correct form.

Binary Shifts

A binary shift moves all the bits in a binary number left or right by a set number of places.

  • A left shift moves all bits to the left, filling the empty right-hand bits with zeros. Each left shift multiplies the number by 2. For example, shifting 0001 0100 (20) one place left gives 0010 1000 (40).

  • A right shift moves all bits to the right, discarding the rightmost bits. Each right shift divides the number by 2. For example, shifting 0010 1000 (40) two places right gives 0000 1010 (10).

Masks

A mask is a binary pattern used with bitwise operations (such as AND, OR and XOR) to manipulate specific bits within a binary value.

  • An AND mask is used to clear (set to 0) specific bits. Any bit ANDed with 0 becomes 0, and any bit ANDed with 1 stays the same. For example, 1011 0110 AND 0000 1111 = 0000 0110 - the mask keeps only the lower four bits.

  • An OR mask is used to set (turn on) specific bits. Any bit ORed with 1 becomes 1, and with 0 stays the same. For example, 1010 0000 OR 0000 1111 = 1010 1111.

  • An XOR mask is used to toggle (invert) specific bits. Any bit XORed with 1 flips (0 → 1 or 1 → 0), while XORed with 0 stays the same. For example, 1010 1010 XOR 0000 1111 = 1010 0101.

Character Sets

A character set is a collection of characters (letters, numbers, symbols and control codes) that a computer can recognise, store and process. Each character is represented by a unique binary code.

ASCII (American Standard Code for Information Interchange) is an early character set that uses 7 bits to represent 128 characters, including English letters, digits, punctuation and control characters. It’s simple and compact but limited to English and basic symbols. Extended ASCII uses 8 bits for 256 characters.

Unicode was developed to overcome ASCII’s limitations by representing characters from all languages and writing systems. It uses up to 32 bits and includes over 140,000 characters, allowing consistent representation of text across different devices and platforms.

noun-arrow-688116e.png
noun-binary-code-7032556e.png
noun-arrow-688116f.png
noun-text-7266622.png

This page is under active development.

Check here for the latest progress update.

noun-under-construction-7744129e.png
logoheadwhite.png

Questo's Key Terms

Data Types: integer, real, Boolean, character, string

Number Systems: binary, denary (decimal), hexadecimal, sign and magnitude, two's complement, binary addition, binary subtraction, floating point, floating point normalisation, floating point addition, floating point subtraction

Binary shifts: left shift, right shift

Masks: mask, bitwise operator, AND, OR, XOR
 

Character Sets: character set, ASCII, Unicode

Did You Know?

Gottfried Wilhelm Leibniz, a German mathematician, is credited with inventing the binary number system in the 17th century, hundreds of years before computers existed. Leibniz biscuits are named after him.

noun-biscuit-5833333e.png

© CSNewbs 2025

The written, video and visual content of CSNewbs is protected by copyright. © 2025
bottom of page