Data types (unit 6) (Finished) Flashcards
(6.1) What is a primitive data type?
A primitive data type is one which is provided by (or built into) a programming language
(6.1) What are some examples of primitive data types
Integer
real/float
boolean
(6.1) Why are data types important?
Because all data types are held in binary, so knowing the data type of the number is extremely important
(6.1) Why do some variables need to be defined?
some variables need their data types defining so that they can be properly utilized
Such as in Java
(6.1) What is base 10?
Denary- only uses 10 numbers to create every number
(6.1) What is base 2?
Binary- only uses 1s and 0s
(6.1) What is base 16?
Hexadecimal- uses 1-9 and A-F for 10-15
(6.1) How is denary converted to hex?
divide by 16 and add the remainder as a separate number
eg 43/16= 2 remainder 11
because 11= b the answer is 2b
to check that this is correct we can do
2*16= 32 + b(11)= 43
(6.1) How is binary converted to hexadecimal?
binary number is split into 2 bits and a number is made of each
eg 11101011 = 1110 1011
1110 = 14= E
1011 = 11 = B
EB
(6.1) What is hexadecimal used in?
RGB colour codes
MAC addresses
Memory locations
(6.1) Why is hex used?
A hexadecimal value is much easier to read and remember than a string of binary digits
It is quicker to write or type, since a hex digit takes up only one character, not four
There is less chance of making an error when typing hex characters than a string of 1s and 0s
It is very easy to convert to and from binary
(6.2) In what way are computers similar to light bulbs?
Data is stored and processed using combinations of ON and OFF voltages, equivalent to a lamp turning on and off where ON = 1 and OFF = 0
(6.2) What is a bit?
Each individual digit in a binary value is referred to as a bit, (from the term binary digit)
(6.2) What is a byte?
A byte is a collection of 8 bits
Two or more bytes can be grouped together to hold larger values
(6.2) What are the names and amounts for types of bytes?
kilo(kB)- 1.000
mega(MB)- 1,000,000
giga(GB)- 1,000,000,000
tera(TB)- 1,000,000,000,000
(6.2) What is ASCII code?
American Standard Code for Information Interchange, (ASCII,)- used to encode symbols found in the English alphabet
Had limitations due to the amount of characters it could contain
(6.2) why are numerical characters not always the same binary value as their converted value?
because not all numbers are going to be used in a numerical/mathematical way. For example, a house number in a database full of addresses
(6.2) What is Unicode?
Standardises the encoding of characters from all languages
(6.2) What are some advantages of Unicode?
Every character in every language can be represented
(6.3) How does binary addition work?
add the digits in the same columns, carry when the value is >1
(6.3) What is the problem with adding binary values?
it can cause overflow errors
(6.3) What is the formula for calculating the range of which a number of binary values can represnet?
2(to the power of n)- 1
(6.3) How are negative numbers represented in binary?
Sign and magnitude
Two’s compliment
(6.3) What is sign and magnitude?
the first bit is taken and used as an indicator for the value being negative
This means that the value represented is smaller
In addition to this, arithmetic doesn’t work properly with this method, so Two’s compliment is much more common
(6.3) What is two’s compliment?
most popular method of representing negative binary numbers
Done by flipping the binary digits and adding one
eg 01010101 (85) = 10101010 + 1 = 10101011 (-85)
(6.3) Find -77 in two’s compliment (method of twos compliment)
Find the positive- 01001101 = 77
Flip the bits- 10110010
Add 1- 10110011 = -77
(6.3) What range of numbers can be represented in negative via two’s compliment?
Half the amount, since the first value is used to indicate the negative value
(6.3) At what point will overflow occur in negative numbers?
above 127 (assuming 8 bits)
(6.3) How can binary fractions be made?
By placing a decimal point in the sequence, separating whole numbers from fraction numbers
(6.3) What is fixed point binary?
The number uses a specific placement for the binary point in order to make decimal numbers
This decreases accuracy however as it is not flexible to the needs of the number
(6.4) What is the problem with fixed point binary numbers?
They have reduced accuracy as they are forced to be centered around one decimal point
(6.4) What is a mantissa?
Holds the main digits of a binary number
(6.4) What is an exponent?
determines where the decimal point should be placed in a floating point binary number
(6.4) What are floating point numbers?
Binary numbers held in more than 8 bits, including:
sign bit- tells if the number is negative or positive (1 bit)
mantissa- stores the actual number (7 bits)
exponent- dictates where the decimal point will be placed (4 bits)
(6.4) How are negative floating point numbers converted to denary?
find the two’s compliment of the mantissa (ADD ONE)
work out the number normally
negative your answer
(6.4) What is normalization?
The process of moving the binary point in order to make the most accurate number possible
(6.4) How is normalization done?
Move the mantissa until the 1st digit after the decimal is a significant figure, minus the number of times moved off of the exponent
(6.4) How are denary numbers converted to normalized floating point binary numbers?
Convert to floating point (find 88 in binary)
Normalize (add decimal point in before 1st significant digit)
(6.4) How are negative denary numbers calculated as normalized floating point binary numbers?
Calculate the binary value
two’s compliment it
normalize it
(6.5) How can bits be manipulated in binary numbers?
shift instructions (left/right shift by a number of bits) masks (NOT, OR, AND, XOR)
(6.5) What is a logical shift left?
MSB (most significant bit) is shifted into the carry bit, and a zero is placed in the LSB (least significant bit) spot
(6.5) What are the uses of a logical shift left?
allows the user to multiply the binary number by two
(6.5) What is a logical shift right?
LSB (least significant bit) is shifted into the carry bit, and a zero is placed in the MSB (most significant bit) spot
(6.5) What are the uses of a logical shift right?
Halves the total value of the binary number
(6.5) What is an arithmetic shift right?
same as a logical shift right, except the space left by shifting the LSB is replaced with the MSB where a 0 would normally go
(6.5) What is an arithmetic shift left?
like a logical shift left, except the sign bit is preserved and a zero moves into the empty space at the end of the sequence
(6.5) How is multiplying binary numbers done?
by arithmetic shifting left a number of times, depending on how many times it needs to be multiplied
(6.5) How is dividing binary numbers done?
arithmetic shift right, rounds down if an odd number is divided by two
(6.5) What is a circular shift right?
the carry bit is moved into the msb and the value in the lsb is moved into the carry bit
(6.5) What is a circular shift left?
the value in the msb is moved into the carry bit and the carry bit into the lsb
(6.5) What is XOR
exclusive OR- if one is true, then the statement is true, but if both are true, then it is false
(6.5) What is boolean logic?
A form of algebra where all values are either true or false
(6.5) What is a mask?
a condition applied to the comparison of two binary strings in order to provide an outcome
(6.5) What is the use of AND mask?
can be used to clear a particular part of a bit
(6.5) What is the use of an OR mask?
Can be used to set a particular bit
(6.5) What is the use of an XOR mask?
Can be used to toggle a particular bit