1.4 Data types, structures and algorithms Flashcards
What is a primitive data type
Basic type is a data type provided by a programming language as a basic building block
What are the common primitive data types (5)
Integer
Floating point/ real
Character
String
Boolean
What do integers hold
Whole numbers
What do floating points/ reals hold
A number with a fractional part
What do characters hold
A single alphanumeric character or special symbol
What do strings hold
Multiple alphanumeric or special symbols
What do booleans hold
The value 0 or 1 sometimes represented by False or True
Why do we use binary
Because computers can only represent values as on or off; because they are reliant on electricity. It is also very reliable ; the computer always receives the correct data.
Why doe we use hexadecimal(4)
Much easier to read than a long string of binary
Quicker to write and take up less space
Less chance of making an error while typing
Very easy to convert to and from binary
What is hexadecimal used for (4)
Colours
MAC addresses
Assembly languages
Machine Code
Define Bit
the smallest unit of data in a computer, holds either a 0 or a 1
Define nibble
A sequence of 4 bits
Define Byte
A sequence of 8 bits
How many bits are required to hold a value of 2^n or below
n
What are the prefixes for bytes
Kilobyte - kB - 10^3
Megabyte - MB - 10^6
Gigabyte - GB - 10^9
Terabyte - TB - 10^9
Kibibyte - kiB - 2^10
Mebibyte - Mib
How do character sets work
Each single alphanumeric and special character is represented by an individual binary value
What is ASCII?
7 bit character set that can hold 128 characters used mostly for english
What is extended ASCII
8 bit character set that can hold 256 characters with extra characters for different langauages
What is Unicode?
16 or 32 bit character set that can hold characters for many languages
What is the comparison operator for equal
==
What is the comparison operator for not equal
<> or !=
What is the comparison operator for greater than
>
What is the comparison operator for less than
<
What is the comparison operator for greater than or equal
> =
What is the comparison operator for less than or equal
<=
What happens when the result of a binary cacluation is greater than the assigned number of bits can hold
Binary overflow error
What is the range of values a binary number can hold with n digits
0 - 2^n -1
What is the most significant bit of a binary number
The first bit
What is sign and magnitude
Method where the most significant bit represents either + (0) or - (1)
Why is sign and magnitude not used
Normal arithmetic does not work properly when using it, meaning more complicated circuits would have to be designed
What is two’s complement?
Method by which the most significant bit is changed from positive to negative
How to convert a number to negative using twos complement
Traverse from right to left until you find the first 1, after this one flip the remaining bits
What is the range of a twos complement number with n bits
-(2^(n-1)) <-> 2^(n-1) -1
What is fixed point binary
Method of storing reals which uses a specified number of bits where the decimal point is fixed
Advantage of fixed point binary
Easier to process
Disadvantage of fixed point binary
Cannot represent the range or accuracy of numbers that may be required
How does the accuracy of a fixed point binary number vary with range
Inversely
What is floating point representation
A method where the decimal place in a number can vary based on the exponent.
What is the mantissa?
The part of a floating point number that holds the actual number
What is the exponent
The part of a floating point number that sets the position of the floating pint
How does floating point work
Floating point starts in between 1st and 2nd bit and exponent moves point to the right x times when the exponent is equal to x. If x is negative then to the left
What is normalisation
The process of moving the floating point to achieve the maximum level of precision for a given number of bits