1. 4. 1 Data Types 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”
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
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|
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
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
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
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
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
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
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
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
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
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
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
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