Back to AI Flashcard MakerInformation Technology /A Level Computer Science Paper 1: 1.4.1 - Data Types - Using binary

A Level Computer Science Paper 1: 1.4.1 - Data Types - Using binary

Information Technology51 CardsCreated about 1 month ago

This flashcard set introduces primitive data types provided by programming languages (such as integers and booleans), explains the denary (decimal) number system, and describes how subscripts indicate the base of numeric values (e.g., base 2, 10, or 16).

Primitive data types

One provided by a programming language

Integer, float, char, string, Boolean

Tap or swipe ↕ to flip
Swipe ←→Navigate
1/51

Key Terms

Term
Definition

Primitive data types

One provided by a programming language

Integer, float, char, string, Boolean

Denary

Base 10/decimal

Our number system

How to know what data type a value is in

It will have 2/10/16 written in subscript

Binary

Uses 1/0 multiplied by the base, starting from the right

The bases are all powers of 2<...

Converting from denary to binary

Put a 1 in the column that is closest to the denary value, subtract and repeat

Hexadecimal

Uses base 16

Letters A-F represent values 10-15

Related Flashcard Decks

Study Tips

  • Press F to enter focus mode for distraction-free studying
  • Review cards regularly to improve retention
  • Try to recall the answer before flipping the card
  • Share this deck with friends to study together
TermDefinition

Primitive data types

One provided by a programming language

Integer, float, char, string, Boolean

Denary

Base 10/decimal

Our number system

How to know what data type a value is in

It will have 2/10/16 written in subscript

Binary

Uses 1/0 multiplied by the base, starting from the right

The bases are all powers of 2

Converting from denary to binary

Put a 1 in the column that is closest to the denary value, subtract and repeat

Hexadecimal

Uses base 16

Letters A-F represent values 10-15

Hexadecimal advantages

Quicker
Easier to understand
Less likely to make errors

Converting hex to denary

Show workings

Convert letters to digits, multiply by base and sum

Converting denary to hex

Divide by 16, add the hex symbol of the remainder assuming 2 bit value

Hex and binary conversions

Each hex value is 4 bits of binary
Convert the hex or binary to digit and then write out as the other
Combine the outputs

Binary addition

Works similar to denary, carry over a 1 if you have to go back to 0

What happens if adding 2 8-bit numbers gives a 9-bit answer?

There is an overflow error and the computer just cuts off the last bit from its output
Clearly indicate this in your answers


Range of Binary Addition

0 -> (2^n) -1 where n is the number of bits

Binary Subtraction

You make the second number into its negative value using Two’s Complement and then add them

Sign and Magnitude

The first bit represents +/- and then the rest are the same

The first bit being a 1 means the number is negative.

Two’s Complement Grid

The leftmost column has the negative value of itself

Sign and Magnitude Range

-(2^(n-1) + 1 -> (2^)n-1)) -1

Two’s Complement Process

  1. Find the positive value

  2. Invert the value of each bit

  3. Add one

Two’s complement range


(2^(n-1)) -> 2^(n-1) - 1

What happens if there is overflow in binary subtraction?

You can ignore those bits

What are the lsb and msb

lsb - least significant bit - the rightmost bit

msb - most significant bit - the leftmost bit

Logical shift left

Pushes every value 1 space to the left, the msb goes into the carry bit, 0 comes into the lsb


Logical shift right

Pushes every value 1 space to the right, the lsb goes into the carry bit, 0 comes into the msb

Logical shift sums

x2 for left, /2 for right as long as it isn’t two’s complement or sign and magnitude


Arithmetic shift left

Pushes every value 1 space to the left but the msb doesn't move so the second bit from the left goes into the carry bit, 0 comes in as lsb

Arithmetic shift right

Pushes every value 1 space to the right and the value that comes into the msb is whatever was there before

Arithmetic shift sums

x2 for left, /2 for right, for all numbers

Circular shift left

Pushes every value 1 space to the left, the msb into the carry bit and the carry bit into the lsb

Circular shift right

Pushes every value 1 space to the right, the lsb into the carry bit and the carry bit into the msb

Bitwise Masks

Apply another binary value with an AND, OR or XOR

| Use boolean algebra on binary values by using each pair of corresponding values

OR masking

0: The output is the same as the input
1: The output is 1 (set the bit)

AND masking

0: The output is 0 (clear the bit)
1: The output is the same as the input

XOR masking

0: The output is the same as the input
1: The output is the opposite of the input (toggle the bit)

Fixed point binary

At a fixed point is a metaphorical decimal point, after that comes negative values of 2


First 5 coefficients after the fixed point

0.5, 0.25, 0.125, 0.0625, 0.03125

How does moving the decimal point affect it?

Having more bits before the decimal point increases the range but decreases the accuracy

What is a floating point binary number made up of

A mantissa and an exponent

| mantissa x 2^exponent

Where is the decimal point at the start in floating point binary?

Between the first 2 bits

Positive floating point -> decimal

  1. Find the value of the exponent

  2. Move the decimal point by that many spaces to the right

  3. Find the value of that as if it was a fixed point decimal

Negative floating point -> decimal

  1. Find the two’s complement of the mantissa

  2. Find the value of the exponent

  3. Move the decimal point that many spaces to the right

  4. Find the value as if it was a fixed point decimal

  5. Put a sign in front of your value

How to know if a mantissa/exponent is negative

It will have a 1 as the msb (in two's complement)

Negative Exponents decimal conversions

  1. Find the value of the exponent remembering the negative left value

  2. Move the decimal point that many places to the left, as if there were all 0s to the left of your number

  3. Find the value as if it was a regular fixed point number

Doing two's complement on a binary number with a point

Add the 1 to the lsb

Normalised positive number

Has a sign bit 0 and a 1 for the next bit

Normalising a positive number

  1. Move the decimal point to the right until it is in front of the 1

  2. Add as many zeroes to the end as you moved right by

  3. Subtract the amount of spaces you moved to the right from the exponent

  4. Write out the normalised number with the mantissa and exponent

Normalised negative number

Has a sign bit 1 and a 0 for the next bit. Leading 1s don't change the value.

Normalising a negative number

  1. Move the decimal point to the right until it is in front of a 0

  2. Add as many zeroes to the end as you moved right by

  3. Subtract the amount of spaces you moved to the right from the exponent

  4. Write out the normalised number with the mantissa and exponent

Positive denary -> floating point binary

  1. Convert it to fixed point binary

  2. Move the decimal point to the left until it is in front of the first 1

  3. Pad the RHS with zeroes to keep the same length if necessary

  4. Set the exponent equal to how many spaces you moved to the left

Negative denary-> floating point binary

  1. Convert the positive number to fixed point (write a 0 at the start)

  2. Take the two’s complement

  3. Convert as you would a positive number

Floating point addition

  1. Convert each floating point number to fixed point binary by shifting the binary point right by the value of the exponent

  2. Sum the two values

  3. Convert back to floating point and normalise

Floating point subtraction

  1. Convert each floating point number to fixed point binary by shifting the binary point right by the value of the exponent

  2. Take the two’s complement of the negative value

  3. Sum the two values

  4. Convert back to floating point and normalise