4.5 Data representation Flashcards
Write down the natural numbers
{ 0, 1, 2, 3, …}
What are ordinal numbers?
Natural numbers used to describe the numerical position of a value. e.g. in the alphabet (1st 2nd etc.)
Why use hexadecimal?
Long sequences of binary digits are hard for humans to read and understand, so hexadecimal is often used as a shorthand
How many bytes in a megabyte?
One million
How many bytes in a mebibyte?
1024^2 (or 2^20)
List the prefixes starting kibi…
- kibi
- mebi
- gibi
- tebi
What is the significance of the leftmost bit in two’s complement?
The most significant bit (leftmost) is the sign bit, which represents a negative number when set to 1
What is 1111…111 in two’s complement binary?
-1
Range of 8 bits for:
1. unsigned binary number
2. two’s complement number
Unsigned: 0 to 255
Two’s complement: -128 to 127
The sum of two 8-bit two’s complement binary numbers can be between ___ and ___
-128 and 127
(Can ignore the overflow in this case)
How to turn a negative number into a positive number in two’s complement (and vice versa)?
- From the right, up to and including the first 1 stays the same.
- Everything other value gets flipped.
(This is the same as flipping everything then adding 1)
How to subtract two binary numbers A - B?
- Convert B into two’s complement
- Add this to A
How can you identify normalised floating point numbers?
Mantissa must begin with 01 or 10
2 advantages of normalisation of floating point numbers
- It maximises precision for a given number of bits
- It ensures that there is a unique representation of each number, making it simpler to test for equality of numbers
If the exponent of a number is negative, what do you need to do to the mantissa when converting from binary to decimal?
Fill in with 0s if the leftmost bit is a 0, and fill in 1s if its a 1.
Advantages of fixed point binary numbers
- More representable numbers, as numbers don’t need to be normalised
- Maximum precision for the given number of bits
- Can be simpler, and faster, to work with
3 advantages of floating point numbers
- Can represent a much larger range of numbers
- The trade-off between range and precision can be tailored to the context the system is being used in
- Additional non-numeric values can be represented using the unnormalised range (e.g. NaN, infinity)
What is meant by the precision of a binary number?
The maximum number of significant digits that can be represented in a number format.
When the result of an arithmetic operation is a real number (e.g. pi), what options are there for storing it in binary?
- Rounding to the nearest representable value
- Truncating
What is absolute error?
The difference between the actual value and the nearest representable value
(always positive)
What is relative error?
The absolute error ÷ the actual value
(could be given as 0.05, 1/20 or 5%)
When does overflow occur?
When a number is too large to be represented using the available number of bits
When does underflow occur?
When a number is too small to be represented using the available number of bits
What is a character set?
A character set is a standardised collection of characters and the bit-patterns used to represent them
How many bits does ASCII use? How many characters can it represent?
- ASCII uses 7 bits to represent characters (hence max 128 characters)
- However, 8 bits are used to store each character (preceding 0)
- The leading 0 sometimes used as parity bit instead
How does ASCII work?
- Each of the characters is assigned a denary character code
- Which is represented and stored in the computer as binary
What is the downside of ASCII?
ASCII is not sufficient to represent all of the languages and scripts used around the world
Why is unicode needed?
- ASCII can’t represent all languages and scripts
- ASCII can’t represent all possible symbols
- The World Wide Web made it important to have a universal international coding system
Which is the most common unicode encoding standard used?
UTF-8
How does UTF-8 (unicode) use variable width encoding?
UTF-8 can be expanded to a greater number of bits when dealing with larger sets of characters
What are the first 128 codes in unicode the same as?
The first 128 codes in ASCII