1. 4. 1 Data Types Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Data Types

A
  • Integer- Whole numbers (1, 234, 123123, 793 etc), useful for counting things
  • Real- Decimal or Negative numbers (-1, 71.5, 5.01, -80.8 etc), useful for measuring things
  • Character- Single symbol (£, %, ^, &, 7, A etc), includes single numbers and letters
  • String- Collection of characters (Rikesh, Hello, World etc), useful for storing text
  • Boolean- Either True or False, useful for only taking two values (state of power button, “On” “Off”
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Binary to Denary

A
  • Binary 0101 0101 to Denary
  • |128| |64| |32| |16| |8| |4| |2| |1|
  • |0| |1| |0| |1| |0| |1| |0| |1|
  • 64 + 16 + 4 + 1 = 85
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Denary to Binary

A
  • Denary 85 to Binary
  • |128| |64| |32| |16| |8| |4| |2| |1|
  • 85 - 128 = -ve (Invalid so put 0)
  • 85 - 64 = 21 (Valid so put 1, continue with 21)
  • 21 - 32 = -ve (Invalid so put 0)
  • 21 - 16 = 5 (Valid so put 1, continue with 5)
  • 5 - 8 = -ve (Invalid so put 0)
  • 5 - 4 = 1 (Valid so put 1, continue with 1)
  • 1 – 1 = 0 (Once at 0 we should have binary value)
  • |0| |1| |0| |1| |0| |1| |0| |1|
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Binary Addition

A
  • 0 + 0 + 0 = 0 (Also 0 + 0 gives same value)
  • 0 + 0 + 1 + 1 (Also 0 + 1 gives same value)
  • 0 + 1 + 1 = 10 (Leave 0 carry the 1) (Also 1 + 1 gives same value)
  • 1 + 1 + 1 = 11 (Leave 1 carry the 1)
  • Add Binary 1011 to Binary 1110, Answer should be 11001
  • Check answer by converting to Denary if you have enough time
  • 1011 = 11, 1110 = 14, 11 + 14 = 25, 11001 = 25, Correct answer
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Hexadecimal to Denary

A
  • Hex 0 to 9 is the same as Denary 0 to 9
  • Hex A, B, C, D, E and F is Denary 10, 11, 12, 13, 14 and 15 respectively
  • To convert Hex 4E7F to Denary for example you would do the following
  • |16^3||16^2||16^1||16^0|
  • |4||E||7||F|
  • 4 * (16^3) + 14 * (16^2) + 7 * (16^1) + 15 * (16^0) = 20095
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Denary to Hexadecimal

A
  • Denary 56 to Hex
  • Convert to Binary first, Denary 56 is Binary 0011 1000
  • Split the Binary into nibbles, Binary 0011 and Binary 1000
  • Convert the nibbles into Hex, Binary 0011 is Hex 3 and Binary 1000 is Hex 8
  • Merge the two Hex values together to get the answer
  • Denary 56 is Hex 38
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Hexadecimal to Binary

A
  • Hex B2 to Binary
  • Split B2 into B and 2 (splitting into nibbles)
  • Hex B is Binary 1011, Hex 2 is Binary 0010
  • Merge the two binary values together to get the answer
  • Hex B2 is Binary 1011 0010
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Binary to Hexadecimal

A
  • Binary 1011 0010 to Hex
  • Split into nibbles (4 bits), 1011 and 0010
  • Convert each nibble to Denary, 1011 is Denary 11 and 0010 is Denary 2
  • Convert the Denary values into Hex, Denary 11 is Hex B and Denary 2 is Hex 2
  • Combine the two Hex values together to get the answer
  • Binary 1011 0010 is Hex B2
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Negative Numbers in Binary- Sign Magnitude

A
  • Add a + or - sign in front of the number
  • Leading 1 represents -ve, leading 0 represents +ve
  • Example, Binary 10101101 is Denary 173
  • Sign Magnitude of this means adding 0 so 010101101
  • If we were to do -173 instead, a 1 is added so 110101101
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Sign Magnitude to Denary

A
  • Example, Sign Magnitude 101101001 to Denary
  • Remove the Leading number (in this case 1) left with 01101001
  • Convert this into Denary, 01101001 is Denary 105
  • Add the sign back to the number (1 is – in this case), Denary -105
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Negative Numbers in Binary- Two’s Complement

A
  • Make most significant bit negative (8 bit, 128–>-128)
  • Converting to Two’s Complement from Binary, flip all bits and add 1
  • What this does is make a number negative
  • Example, Binary 00000111 into Two’s complement
  • Flip the bits (opposite), 00000111 becomes 11111000
  • Add 1, 11111000 becomes 11111001
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Denary to Two’s Complement

A
  • Example, Denary 72 in Two’s Complement
  • |-128| |64| |32| |16| |8| |4| |2| |1|
  • |0| |1| |0| |0| |1| |0| |0| |0|
  • Therefore Denary 72 in Two’s Complement is 01001000
  • Example, Denary -72 in Two’s Complement
  • |-128| |64| |32| |16| |8| |4| |2| |1|
  • |1| |0| |1| |1| |1| |0| |0| |0|
  • Therefore Denary -72 in Two’s Complement is 10111000
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Subtraction in Binary using Two’s Complement

A
  • Subtracting number from other same as adding a negative number
  • Example, Subtract 12 from 8 (8 – 12)
  • Denary 8 is Two’s Complement 01000
  • Denary -12 is Two’s Complement 10100
  • Add these two numbers together to get 11100
  • We can check using Two’s Complement that the answer is correct
  • -16 + 8 + 4 = -4, 8 – 12 = -4, Therefore the answer is correct
  • Remember to discard any overflow if it is present
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Floating-Point Numbers in Binary

A
  • 6.67 x 10^-11, Mantissa (6.67), Exponent (-11)
  • Value 6.67 is shifted 11 times from the decimal point according to M and E
  • Same as Binary but we dedicate single bit to the sign of number (+ve or -ve)
  • The Sign bit (S) represents the sign of the exponent
  • Sign 0 represents +ve number and Sign 1 represents -ve number
  • Place after most significant bit has a decimal point in the mantissa
  • Anything after the decimal place is ½, ¼, 1/8, 1/16 etc
  • The exponent is in Two’s Complement
  • In example above, exponent is 5, we move 5 places to the right
  • Left with mantissa 110010.0111 which is Denary 50.4375
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Another Example of Floating-Point Numbers in Binary

A
  • Exponent is -3, Mantissa is 0.101101000 and sign is 1 (negative)
  • We now get a Mantissa of 0.000101101 (Moved 3 places left)
  • This leaves us with the Denary value 89/1024
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Normalisation

A
  • Floating point numbers normalised, make sure they are precise as possible in given number of bits
  • Makes as much use of the mantissa as possible
  • To normalise binary number, make it start with 01 for +ve number, 10 for -ve number
  • Example- Normalise Binary Number 000110100101 which is a floating-point number with an 8-bit mantissa and a 4-bit exponent
  • Therefore, our mantissa is 00011010 and our exponent is 0101
  • Next adjust mantissa so it starts with 01 or 10, this is a positive number so we need it to start with 01
  • This can be done by shifting the mantissa two places to the left leaving us with 01101000
  • When doing the shift, we fill in the gaps left behind with 0’s
  • Due to the shift being two places, we must reduce the exponent by 2 so that we represent the same number
  • 0101 = 5, 5 – 2 = 3, therefore our new exponent is 0011
  • We have our final positive normalised number below
  • 8-bit Mantissa 01101000 and 4-bit exponent 0011
17
Q

Addition of Floating-Point Numbers

A
  • We must make the two numbers exponents the same to add them together
  • Then we add their mantissa’s together and normalise the result if necessary
  • Example- Add the two floating point numbers below
  • 0 000100 0011 (3)
  • 0 000101 0010 (2)
  • Line up the decimal points together filling any gaps with 0’s
  • 000.100 000.1000
  • 00.0101 000.0101
  • Add the two numbers together to get Mantissa 001101 and Exponent 0010
  • Normalise the result (check this if the number starts with 01 or 10)
  • Mantissa is binary shifted one place to the left giving us Mantissa 011010
  • We then need to reduce the exponent by the number of places, 0010 = 2, 2 – 1 = 1, Exponent 0001
  • This gives us the answer Mantissa 011010 Exponent 0001
18
Q

Subtraction of Floating-Point Numbers

A
  • The same steps are followed but instead of adding the numbers we subtract them
  • Method for subtraction is shown in other flashcard (Flip and add)
19
Q

Bitwise Manipulation and Masks- Shifts

A
  • Shift on binary numbers is called a logical shift
  • Either shift left adding trailing zeros or shift right adding leading zeros
  • Example, 10010110 shifted three places left would be 1000110000
  • Shifting is the multiplication (left shift) or division (right shift) of a number by 2^n where n is the number of places shifted (The example above is a multiplication of the original number by 2^3 = 8)
20
Q

Bitwise Manipulation and Masks- Masking

A
  • Mask applied to binary numbers, combines them with a logic gate
  • Adds the rules of AND, OR and XOR to binary numbers
  • Refer to images in word doc
21
Q

Character Sets for Representing Text

A
  • A character set is a published collection of codes and characters, used by computers to represent text
  • Two widely used character sets are ASCII and Unicode
22
Q

ASCII and Extended ASCII

A
  • American Standard Code for Information Interchange
  • 7-bit represents 128 different characters (Capital letters A-Z represented by codes 65-90)
  • Lower case letters a-z represented to codes 97-122, also codes for numbers and symbols
  • Issue is when other languages and different characters need to be represented
  • Extended ASCII, 8-bit, 256 different characters, represents a little more than standard ASCII
23
Q

Unicode

A
  • 16-bit, represents 1,112,064 different characters (Over a million)
  • Can represent emojis, multiple languages, the solution to ASCII’s issue
  • Problem is a larger memory requirement compared to ASCII