Name each primitive data type
-Integer
-Real/floating point
-Character
-String
-Boolean
What is the purpose of data types?
They are needed so the computer knows how to store, process and interpret data correctly so that only valid operations are performed on data.
What is an integer?
A whole number
What is a real/floating point data type?
A decimal number
What is a character?
A single letter, digit or symbol
What is a string?
A sequence of characters
What is a boolean data type?
A data type with only 2 possible values – true or false
What types of data can be represented in binary?
Numeric, text, image and sound
How is binary used to represent text?
Through their use of the character sets ASCII and Unicode. Each character is given a unique binary code. Increasing the number of bits for each character increases the number of possible characters that can be stored
How is binary used to represent numbers?
Positive denary numbers can be represented through binary. Negative binary numbers can be stored using Sign and Magnitude and Two’s Compliment. Floating point binary can be used to store decimal numbers.
How is binary used to represent images?
Images are split into pixels. Each pixel is given a binary value which represents colour.
How is binary used to represent sound?
Analogue sound is sampled. A sample is a reading that is taken at a certain point and stored as a binary number.
Why do computers use binary?
Computers are made up of switches which have 2 states: on and off. This can be easily represented using binary as it also has 2 states that can represent on and off: 1 and 0.
Describe Sign and Magnitude
The number is written the same as in regular binary, however the left-most bit has become a sign bit (no longer representing a weighted value, but instead a sign) with 1 representing a negative number and 0 for if the number is positive.
Describe Two’s complement
Negative numbers are represented starting from 11111111 as the denary value -1.
Starting from the right-most digit, you write the binary number exactly how it would appear in regular binary, up to and including the first 1. From that point onwards, swap every 0 for a 1 and vice versa.
State the advantages of storing values using Two’s complement rather than Sign and Magnitude
Describe how to do binary subtraction using the borrowing method
1 - 1 = 0
1 - 0 = 1
0 - 0 = 0
0 - 1 = 1, make the next digit of 1 a 0 and the digit to the right of it a 2
Describe how to do binary subtraction using Two’s complement
Add the negative version of one number to the positive of the other number to get the two’s complement form of the result.
[a - b = a + (-b)]
What are the benefits of using hexadecimal over binary?
-Hexadecimal values are shorter than binary so 4 bits can be represented using one character
-This means they are faster, and more reliable to write down and read
How are decimal numbers represented in floating point binary?
The mantissa of a floating point number holds the actual digits of the value and represents the precision of the number. It’s usually 5 bits long.
The exponent controls the size of the number as it governs where the decimal point is positioned. It’s usually 3 bits long. The exponent is written in Sign and magnitude.
The decimal point starts between the first and second digits. If the exponent is positive the decimal moves right, if it’s negative it moves left.
Each digit after the decimal represents 1/2^n (with n increasing the lower the digit is).
What is the benefit of using a normalised form when representing data as a floating point number?
Describe how a normalised number should appear
A floating point where the mantissa starts with 01 if positive or 10 if negative.
The normal exponent should be the difference between where the decimal point would be based on the original exponent and where it is after normalisation (negative if the normalised is further right, positive if it’s further left)
How do you perform a logical shift?
By moving all the bits in a binary number left/right a set number of places.
In a right shift, the right most bits should be discarded. In a left shift, the empty righthand bits should be filled with zeros.
What do right and left shifts do to the numbers?
A right shift divides the number by 2, a left shift multiplies the number by 2.