(4.5) Fundamentals of data representation Flashcards
What are natural numbers? (ℕ)
Positive integers
(including 0)
number set ℕ = {0, 1, 2, 3, … }
What are integers? (ℤ)
Whole numbers
number set ℤ = { …, -3, -2, -1, 0, 1, 2, 3, … }
What are rational numbers? (ℚ)
Numbers that can be written as fractions (ratios of integers), including integers (ex 7; 7/1)
What are irrational numbers?
Numbers that cannot be written as a fraction (ex √2, √3, √5, √7, √11, √13, √17, √19)
What are real numbers? ( ℝ)
possible real world quantities
includes natural, rational and irrational numbers
numbers that are not real include imaginary numbers (ex e or i)
What are ordinal numbers?
ordinal
numbers are used to tell an objects numerical position in a list (ex 1st, 2nd, 3rd, etc)
What type of numbers are used for:
-counting
-measurements
Counting - natural numbers
Measurements - real numbers
Why is hexadecimal (base 16) used as shorthand for binary (base 2)?
- large numbers can be represented using fewer digits
- easier to understand and remember
(colour values and MAC addresses are often represented in hex)
How do you work out how many values can be represented with n bits?
2^n
ex if n=3, 2^3 = 8
(000 001 011 111 010 110 101 100)x8
How can quantities of bytes be described using binary prefixes representing powers of 2
(ex 1KiB = 2^10)
- kibi, Ki - 2^10
- mebi, Mi - 2^20
- gibi, Gi - 2^30
- tebi, Ti - 2^40
How can quantities of bytes be described using decimal prefixes representing powers of 10
(1kB = 10^3)
- kilo, k - 10^3
- mega, M - 10^6
- giga, G - 10^9
- tera, T - 10^12
Historically innacurate use of units
Historically the terms kilobyte, megabyte, etc
have often been used when kibibyte, mebibyte,
etc are meant
In unsigned binary, what are the minimum and maximum values for a given number of bits (n) ?
0 and (2^n)-1
ex bits = 4
Minimum value = 0
Maximum value = (2^4)-1 = 15
Adding two (unsigned) binary integers
010010
100100
110110
0 + 0 = 0
1 + 0 = 1
1 + 1 = 10 (0 carry the 1)
1 + 1 + 1 = 11 (1 carry the 1)
Multiplying two (unsigned) binary integers
10100
x —10
—00000
101000
0101000
0 x 0 = 0
0 x 1 = 0
1 x 1 =1
How to represent negative and positive integers in two’s complement (Signed binary)
Positive
-128 64 32 16 8 4 2 1
—0—1—1—1-0-1-0-1
= (64+32+16+4+1) = 117
The most significant bit is always 0
Negative
-128 64 32 16 8 4 2 1
–1– 0—0—0–1-0-1-1
= (-128+8+2+1) = -117
The most significant bit (negative) is always 1
Converting binary from unsigned to signed
Unsigned
01110110 = 177
Signed
10001010 = -117
From the least significant bit, keep the binary digit the same up to and including the first 1, after which switch a 1 to a 0/ a 0 to a 1.
Performing subtraction using two’s complement
165 - 23 = ?
1) Convert the number being subtracted (23) into negative signed binary
00010111 = 23
11101001 = -23
2) Add together the positive binary number (165) and the negative number (-23)
-10100101
-11101001
110001110
3) If there is overflow with subtraction, ignore the most significant figure
so 110001110
= 10001110 = 142
165 + -23 = 142
Minimum and maximum ranges of values that can be represented in signed and unsigned binary
Unsigned
Min = 0
Max = (2^n) -1
ex 3 bit
Min = 000 = 0
Max = 111 = (2^3) -1 = 7
Signed
Min = -2^(n-1)
Max = 2^(n-1) -1
ex 3 bit
Min = 100 = -2^(3-1) = -4
Max = 011 = 2^(3-1)-1 = 3
Representing numbers with fractional points in binary
Fixed point form binary:
-16 8 4 2 1 . 1/2 1/4 1/8
0 0 1 1 1 1 1 0 = 7.75 (4+2+1+1/2+1/4)
Disadvantages:
-range of numbers that can be stored is limited as some bits are being used for fractional part of the number
-Some numbers cannot be stored accurately (ex 1/3, recurring, etc)
Floating point binary:
-8 4 2 1 . 1/2 1/4 1/8 1/16
-64 32 16 8 4 2 1 . 1/2
(both use 8 bits - but can represent a wider range of magnitudes using the same number of bits, or allow for more relative precision for smaller numbers in the range)
Mantissa (number being stored, always in two’s complement)
Exponent (binary point position, always in two’s complement)
ex -4 2 1
1 1 0
=move binary point 2 to the left (because negative)
Advantages and disadvantages of fixed point and floating point
Range:
Floating point can represent a wider range of magnitudes than a fixed-point number using the same number of bits
Precision:
Floating point also allows for more relative precision for smaller numbers in the range.
Speed of calculation:
Fixed point can be faster and/or use less hardware than floating point
Why are both fixed point and floating point representation of decimal numbers inaccurate?
There are many numbers that binary cannot accurately represent, not exactly.