Data Types — OCR A-Level Computer Science
Data Types explained
Data Types covers 10 specification points, including (a) Primitive data types, integer,… and (b) Represent positive integers in binary..
Read the full explanation
Open a point below for its explanation and revision guidance.
(a) Primitive data types, integer, real/floating point, character, string and Boolean.
This statement names the primitive data types you must know: integer, real/floating point, character, string and Boolean. Primitive types are the basic built-in types a language provides directly. An integer stores whole numbers exactly, within a range set by the number of bits allocated. A real or floating point value stores numbers with a fractional part using a mantissa and exponent, so it is usually approximate. A character holds one symbol, stored as a numeric code such as ASCII or Unicode. A string is a sequence of characters. A Boolean holds only true or false. Method: for each type, state what it stores, give one example value, and explain why a programmer would choose it.
(b) Represent positive integers in binary.
Representing a positive integer in binary means writing it as a pattern of bits, where each bit position has a place value that is a power of two. Counting from the right, the place values are 2⁰ = 1, 2¹ = 2, 2² = 4, 2³ = 8, 2⁴ = 16 and so on. To convert 13, find the largest place value that fits: 8 (2³) leaves 5, then 4 (2²) leaves 1, then 1 (2⁰) leaves 0. Set the bits for 8, 4 and 1 to give 1101, with every other bit set to 0. Check the result by adding the set place values back to 13. The number of bits limits the range: an n-bit unsigned pattern holds values from 0 to 2ⁿ − 1, so 8 bits give 0 to 255. Positive integers in this representation need no sign bit.
(c) Use of sign and magnitude and two’s complement to represent negative numbers in binary.
Negative integers need the sign to be stored within the bit pattern. In sign and magnitude, the leftmost bit is the sign bit (0 for positive, 1 for negative) and the remaining bits hold the magnitude. For −5 in 8 bits, the magnitude 5 is 0000 0101, so the pattern is 1000 0101. Sign and magnitude gives two zeros and an 8-bit range of −127 to +127. Two's complement is the usual method in modern computers: take the positive value, invert every bit, then add 1. For −5, 0000 0101 inverts to 1111 1010, and adding 1 gives 1111 1011. The leftmost bit has place value −2⁷ = −128, so the pattern equals −128 + 64 + 32 + 16 + 8 + 2 + 1 = −5. The 8-bit range is −128 to +127 with a single zero.
(d) Addition and subtraction of binary integers.
This statement asks you to add and subtract binary integers by working column by column from the least significant bit. For addition, apply 0+0=0, 0+1=1, 1+0=1 and 1+1=10, writing the 0 and carrying 1 leftwards; in a column with a carry-in, 1+1+1=11. Example: 1010 + 0111 = 10001 (10 + 7 = 17), so the carry creates a fifth bit. For subtraction, use a stated method such as borrowing from the next 1 to the left, or adding the two's complement of the second number. Example: 1101 − 0110 = 0111 (13 − 6 = 7). Check every answer by converting operands and result to denary, and note whether the result fits the bit length required.
(e) Represent positive integers in hexadecimal.
This statement asks you to represent positive integers in hexadecimal, a base-16 system using digits 0 to 9 and letters A to F, where A=10, B=11, C=12, D=13, E=14 and F=15. Convert binary by grouping digits into fours from the right, padding with leading zeros if needed: 1011 0110 becomes B6. Check using place values: B6 = 11×16¹ + 6×16⁰ = 182. To convert denary, repeatedly divide by 16 and record the remainders, then read them in reverse order: 182 ÷ 16 = 11 remainder 6, and 11 is B, giving B6. Hexadecimal is used because it compactly represents long binary values such as memory addresses and colour codes. Only positive integers are required here.
(f) Convert positive integers between binary hexadecimal and denary.
This statement requires you to convert positive whole numbers between three bases: binary (base 2), hexadecimal (base 16) and denary (base 10). Each hexadecimal digit represents exactly four binary digits, so the binary value 1011 0110 splits into the groups 1011 and 0110, which give B and 6, so the hexadecimal value is B6. Converting denary to binary can be done by subtracting place values such as 128, 64, 32, 16, 8, 4, 2 and 1, or by repeated division by 2 and reading the remainders from bottom to top. For example, 173 is 128 + 32 + 8 + 4 + 1, giving 10101101 in binary. Splitting that into 1010 and 1101 gives A and D, so the hexadecimal value is AD. Check every answer by converting it back to denary. The scope is positive integers, so negative values are not part of this statement.
(g) Representation and normalisation of floating point numbers in binary.
This statement covers how floating-point numbers are represented and normalised in binary using two's complement. In OCR H446, a floating-point value consists of a two's complement mantissa (representing a fractional value) and a two's complement exponent (representing the power of two). Normalisation maximises precision by using the available bits efficiently and provides a unique representation for each value. In normalised form, the first two bits of the mantissa must be different: a normalised positive number starts with 01 (representing 0.1...), and a normalised negative number starts with 10 (representing 1.0...). To normalise an unnormalised binary value, shift the mantissa left or right until the first two bits differ, and adjust the signed exponent accordingly.
(h) Floating point arithmetic, positive and negative numbers, addition and subtraction.
This statement covers floating point arithmetic with positive and negative numbers, including addition and subtraction. A floating point number has a sign, a mantissa and an exponent; 13.5 is held in normalised binary as 0.11011 × 2⁴. The sign indicates whether the value is negative, so apply it when working with negative numbers. To add, align exponents by shifting the smaller-exponent mantissa right: 0.101 × 2³ + 0.11 × 2¹ becomes 0.101 × 2³ + 0.0011 × 2³, giving 0.1101 × 2³ (6.5). To subtract, align in the same way and subtract the mantissas: 0.101 × 2³ − 0.0011 × 2³ gives 0.0111 × 2³, normalised to 0.111 × 2², which is 3.5. Always normalise the result.
(i) Bitwise manipulation and masks: shifts, combining with AND, OR, and XOR.
This statement covers bitwise manipulation on binary values using shifts and masks, with bits combined by AND, OR and XOR. A left shift moves bits towards the most significant end and fills vacated positions with zeros: 0000 0110 << 2 gives 0001 1000, which is 6 becoming 24. A right shift moves bits towards the least significant end: 0000 0110 >> 1 gives 0000 0011, which is 6 becoming 3. A mask is a bit pattern used with a bitwise operator to select, set or toggle particular bits. AND with 0000 1111 keeps the lower four bits: 1011 0110 AND 0000 1111 gives 0000 0110. OR with 0000 0001 sets the least significant bit: 1011 0110 OR 0000 0001 gives 1011 0111. XOR with 1111 1111 inverts every bit: 1011 0110 XOR 1111 1111 gives 0100 1001.
(j) How character sets (ASCII and UNICODE) are used to represent text.
This statement asks you to explain how character sets are used to represent text in a computer. A character set is an agreed table that maps each character to a numeric code, and the computer stores that number rather than the glyph. ASCII is the smaller set, using 7 bits to give 128 codes for English letters, digits, punctuation and control characters. UNICODE is a much larger standard that assigns code points to characters from many writing systems, and encodings such as UTF-8 store those code points in one to four bytes. For example, the uppercase letter A has ASCII code 65, binary 01000001. Link the choice of set to the need for consistent text across languages and devices.
Your focus
- Identifies the value each primitive data type stores.
- Explains why real or floating point values are usually stored approximately.
- Selects an appropriate primitive data type for a given data item.
Show all 30 objectives
- Convert a given positive denary integer to binary using place values.
- Identify the unsigned range of an n-bit binary pattern.
- Verify a binary conversion by summing the place values of the set bits.
- Represent a given negative denary integer in 8-bit sign and magnitude.
- Represent a given negative denary integer in 8-bit two's complement using the invert-and-add-one method.
- Decode an 8-bit two's complement pattern to its denary value using −2⁷ for the leftmost bit.
- Add two four-bit binary integers column by column, including carries.
- Subtract one four-bit binary integer from another using a stated method.
- Identify when an addition produces a result that needs an extra bit.
- Convert a four-bit binary pattern to a single hexadecimal digit.
- Convert a positive denary integer to hexadecimal by repeated division by 16.
- Convert a two-digit hexadecimal value such as B6 to its denary equivalent.
- Convert a positive denary integer to binary by subtracting place values.
- Convert a binary integer to hexadecimal by grouping digits in fours from the right.
- Convert a hexadecimal integer to denary by applying place values of 16 to each digit.
- Explain the purpose of normalisation in floating-point binary representation.
- State the normalisation conditions for positive (01) and negative (10) two's complement mantissas.
- Convert and normalise floating-point values given specific bit widths for mantissa and exponent.
- Represent a denary number such as 13.5 in normalised floating point form.
- Add and subtract two floating point numbers, showing exponent alignment and normalisation.
- Explain why exponents must be aligned before mantissas are added or subtracted.
- Apply a left or right shift to an 8-bit binary value and state the denary effect.
- Use AND, OR and XOR with a mask to isolate, set or toggle specified bits.
- Explain why a mask must contain the correct bit value in each position for the required operation.
- Explain how a character set maps characters to numeric codes stored by a computer.
- Compare the range and purpose of ASCII and UNICODE using correct figures and terms.
- Give a correct worked example of a character's code in ASCII and describe its binary form.
Data Types exam tips
Marking Points
- Identifies integer as the primitive type for whole numbers, with a range set by the number of bits allocated.
- Explains that real or floating point values store fractional numbers approximately, using a mantissa and exponent.
- Distinguishes a character, a single symbol, from a string, which is a sequence of characters.
- Identifies Boolean as the primitive type that holds only true or false.
- Assigns each bit a place value of 2ⁿ, starting at 2⁰ for the rightmost bit.
- Selects the largest place value that fits the remaining amount at each step.
- Produces a bit pattern of sufficient length to hold the value, such as 1101 for 13.
- Checks the answer by adding the place values of the set bits to confirm the original integer.
- Recognises the unsigned range of an n-bit pattern as 0 to 2ⁿ − 1.
- Identifies the leftmost bit as the sign bit, with 0 for positive and 1 for negative in sign and magnitude.
- Stores the magnitude in the remaining bits, so −5 in 8-bit sign and magnitude is 1000 0101.
- Applies two's complement by inverting all bits of the positive value and adding 1, giving 1111 1011 for −5.
- Gives the leftmost bit of an 8-bit two's complement pattern the place value −2⁷ = −128.
- States the range of an n-bit sign and magnitude pattern as −(2ⁿ⁻¹ − 1) to +(2ⁿ⁻¹ − 1) and of an n-bit two's complement pattern as −2ⁿ⁻¹ to 2ⁿ⁻¹ − 1.
- Aligns the binary operands by place value and works from the least significant bit leftwards.
- Applies the binary addition rules correctly, including 1+1=10 with a carry of 1 into the next column.
- Carries the carry-in correctly through each column, including the three-input case 1+1+1=11.
- Performs subtraction by a stated valid method, such as borrowing or adding the two's complement, and applies it consistently.
- Recognises when an addition result needs an extra bit beyond the operand length and reports it.
- Checks the final answer by converting the operands and result to denary.
- Converts a positive integer to hexadecimal by repeated division by 16 and correct reading of remainders.
- Uses the digits 0 to 9 and letters A to F, with A=10 through F=15, correctly.
- Assigns place values of 16⁰, 16¹ and so on when converting hexadecimal to denary.
- Groups binary digits into fours from the right, padding with leading zeros where needed.
- Verifies the hexadecimal value by recalculating its denary equivalent.
- Identifies the base of each number before converting, because 1010 in binary and 1010 in denary represent different values.
- Groups binary digits into sets of four from the right when converting to hexadecimal, adding leading zeros where needed.
- Maps hexadecimal digits A to F to the denary values 10 to 15 when converting from hexadecimal.
- Uses place values or repeated division correctly when converting from denary to binary.
- Checks the final answer by converting it back to denary.
- Identifies that both the mantissa and the exponent are represented using two's complement signed binary.
- Explains that normalisation ensures maximum precision and provides a unique binary representation for each value.
- States that a normalised positive mantissa starts with 01 and a normalised negative mantissa starts with 10.
- Shifts the mantissa until the first two bits differ and adjusts the two's complement exponent by the shift count.
- States that a floating point number is stored as a sign, a mantissa and an exponent, and identifies what each part contributes.
- Normalises a result so the mantissa begins with a leading 1 after the binary point, such as 0.1101 × 2³.
- Aligns exponents before adding or subtracting mantissas, shifting the smaller-exponent mantissa right by the exponent difference.
- Applies the sign of each operand correctly when a negative value is added or subtracted.
- Checks a result by converting it back to denary, for example showing that 0.1101 × 2³ equals 6.5.
- Identifies the effect of a left or right shift on a binary value, including the bits that fill the vacated positions.
- Uses AND with a mask to isolate specified bits, producing zeros in the positions the mask clears.
- Uses OR with a mask to set specified bits to 1 while leaving the other bits unchanged.
- Uses XOR with a mask to toggle specified bits, inverting each bit where the mask bit is 1.
- Works bit by bit across both patterns, keeping them aligned to the same number of bits.
- Explains that a character set maps each character to a numeric code that the computer stores and processes.
- Identifies ASCII as a 7-bit set giving 128 codes for English letters, digits, punctuation and control characters.
- Describes UNICODE as a much larger standard that assigns code points to characters from many writing systems and symbols.
- Explains that UTF-8 and UTF-16 are encodings that store UNICODE code points using a variable number of bytes.
- Gives a correct example, such as ASCII code 65 for the letter A, to show the mapping from character to code.
- Links the choice of character set to the need for consistent text handling across languages and devices.
Examiner Tips
- 💡Match each type to the kind of value it stores, not only to its name.
- 💡For multiple-choice items, eliminate options that give a type the wrong kind of value, such as fractions in an integer.
- 💡Remember that this statement lists string as a primitive type, even though some languages treat strings differently; answer according to the specification.
- 💡Write the place values above the bit positions before converting so that each choice is visible.
- 💡Verify every conversion by adding the place values of the 1 bits and confirming the denary total.
- 💡Memorise the powers of two up to 2⁸ = 256 so that the largest fitting place value is quick to identify.
- 💡Write the bit length first, because the ranges for both methods depend on n.
- 💡Check a two's complement answer by confirming the leftmost bit is 1 for a negative value and that the place-value sum equals the original integer.
- 💡Learn the 8-bit ranges as a quick reference: −127 to +127 for sign and magnitude and −128 to +127 for two's complement.
- 💡Write carries in small figures above the next column so they remain visible as you work.
- 💡Check addition by converting to denary: 1010 (10) + 0111 (7) must give 10001 (17).
- 💡When subtracting, show your chosen method and state the bit length you are working in so each step can be followed.
- 💡Memorise the values of A to F and the sixteen four-bit patterns from 0000 to 1111 to speed up grouping.
- 💡Verify your answer with place values: B6 = 11×16¹ + 6×16⁰ = 182.
- 💡Pad a binary number with leading zeros to a multiple of four bits before grouping.
- 💡Write the place values down in a row before converting, so you can tick off each one as you use it.
- 💡When converting between binary and hexadecimal, rewrite the binary number in groups of four before looking up any digit.
- 💡Convert your answer back to denary as a final check, because this catches most place value slips in a short time.
- 💡Remember the rule for normalised mantissas: the sign bit and the bit immediately following it must differ (01 for positive, 10 for negative).
- 💡Always check the bit allocations specified in the question for the mantissa and exponent before writing the final binary representation.
- 💡Verify both the sign of the mantissa and the sign of the exponent when converting between normalised floating point and denary.
- 💡Write each alignment step in full so you can check the exponent difference before moving any digits.
- 💡Convert your final answer back to denary and compare it with the original values, such as 5 + 1.5 = 6.5.
- 💡Normalise every final answer before you write it down, because an unnormalised answer may lose marks.
- 💡Write the mask directly beneath the value and work through each column in turn to avoid slips.
- 💡Check each answer by confirming that the bits you meant to keep, set or toggle have the correct result.
- 💡Convert a shifted result to denary to check it, such as 0000 0110 << 2 giving 24.
- 💡Name both ASCII and UNICODE and state one clear difference in range, such as 128 codes versus a much larger code space.
- 💡Include one concrete example, such as the ASCII code 65 for A, to show how a character maps to a number.
- 💡Link the use of each character set to a purpose, such as storing text in a multilingual document, rather than listing facts alone.
Common Mistakes
- Describes real numbers as exact; correct this by stating that floating point storage is usually approximate.
- Treats a string as a single character; correct this by stating that a string is a sequence of characters.
- Assigns a fractional value such as 2.5 to an integer type; correct this by choosing real or floating point for fractional values.
- Reads the rightmost bit as the most significant bit, so 13 is misread as 1011; correct by labelling place values from the right as 2⁰, 2¹, 2² and so on.
- Fills in bits from left to right without tracking the remaining value, producing 1110 for 13; correct by subtracting each place value that is used.
- Assumes an 8-bit pattern holds values only up to 127, forgetting that the unsigned range extends to 255; correct by using 2⁸ − 1 = 255.
- Inverts the bits but forgets to add 1, giving 1111 1010 for −5; correct by adding 1 after the inversion.
- Treats the sign bit in sign and magnitude as a value bit, reading 1000 0101 as 133; correct by reading the leftmost bit as the sign only and the remaining bits as magnitude 5.
- Assumes any two's complement pattern starting with 1 is a large negative value, reading 1111 1111 as −255; correct by using the place value −128 for the leftmost bit, which gives −1.
- Writes 1+1 as 0 and forgets to carry 1 into the next column; carry the 1 leftwards.
- Treats 1+1 as 2 in binary; write 10 in the column, which represents 2 in denary.
- Works from the most significant bit rightwards; begin at the least significant bit and move leftwards.
- Ignores the carry bit when the result exceeds the operand length; keep the extra bit in the answer.
- Treats the letter B as 2 or 12 rather than 11; check the letter-to-value table each time.
- Reads remainders in the order they were produced; write them from last to first.
- Groups binary digits from the left, which shifts the values; group in fours from the right.
- Uses letters beyond F, such as G, as hexadecimal digits; the valid digits are 0 to 9 and A to F.
- Groups binary digits from the left rather than the right, which produces the wrong hexadecimal digits; correct by starting each group of four at the least significant bit.
- Treats hexadecimal digits A to F as invalid or reads them as ordinary digits; correct by mapping A to 10 and F to 15 before doing place value arithmetic.
- Records remainders in the order they were found when using repeated division; correct by reading the remainders from bottom to top.
- Omits leading zeros when grouping, so the final hexadecimal digit is misplaced; correct by padding the group with zeros on the left.
- Assumes a value written in one base can be read as denary without checking; correct by stating the base of each number in the working.
- Assumes normalisation only applies to positive numbers by looking for a leading 1; normalised negative numbers in two's complement start with 10.
- Omits the sign bit when writing the exponent in binary; the exponent is a two's complement signed integer and must include its sign bit.
- Shifts the mantissa without adjusting the exponent, altering the numerical value; adjust the exponent to match every shift.
- Adds mantissas without aligning exponents first, which produces an incorrect sum; align the exponents before any addition.
- Shifts the larger-exponent mantissa instead of the smaller one, which changes the value; shift the smaller-exponent mantissa right and increase its exponent by the same amount.
- Treats the sign as part of the magnitude when reading a negative value, which gives a wrong result; read the sign separately and apply it to the whole value.
- Leaves a result unnormalised, such as 0.0111 × 2³, which is not standard form; shift the mantissa left and reduce the exponent until the leading digit is 1, giving 0.111 × 2².
- Confuses left and right shifts, so the value moves the wrong way; left shifts multiply by a power of two and right shifts divide by one.
- Uses OR to clear bits, which sets them instead; use AND with a mask containing 0 in each bit position to clear.
- Applies XOR when a bit must be set, which turns existing 1s into 0s; use OR with a mask containing 1 in each bit position to set.
- Ignores the width of the values, so patterns of different lengths are misaligned; pad both to the same number of bits first.
- Claims that ASCII can represent every character in a modern language; correct this by stating ASCII's limited 128-code range and identifying UNICODE as the set for wider coverage.
- Confuses a character with its code by saying the computer stores the letter's shape; correct this by stating the computer stores the numeric code and the font draws the glyph.
- Treats UNICODE as a single fixed one-byte-per-character encoding; correct this by noting that UTF-8 uses between one and four bytes per code point.
- Assumes standard ASCII uses 8 bits for every character; correct this by stating standard ASCII uses 7 bits.