Data Types Flashcards
What is an Integer
- A whole number
- Zero is an integer
- Negative numbers are integers
- Can’t have a fractional part
What is a Real Number
- Positive or negative numbers
- Can have a fractional part
What is a Character
- A single symbol used by a computer
- The letters A to Z
- The numbers 0 to 9
- Symbols like %, £, and,
What is a String
- A collection of characters
- Can be used to store a single character or many characters in succession
- Don’t cut off leading 0s like numeric types
What is a Boolean
Value restricted to True and False
What are the names for how binary is stored
- Bit - single binary digit
- Nibble - 4-bits grouped together
- Byte - 8-bits or 2-nibbles grouped together
What are the Binary Addition Rules
- 0 + 0 = 0
- 0 + 1 = 1
- 1 + 0 = 1
- 1 + 1 = 0 carry 1
Convert the following Binary to Decimal
- 0110 1010
- 0000 1000
- 0001 1001
- 1100 0010
- 0101 0100
0110 1010 - 106
0000 1000 - 8
0001 1001 - 25
1100 0010 - 194
0101 0100 - 84
Convert the following Decimal to Binary
- 10
- 84
- 160
- 53
- 137
10 - 0000 1010
84 - 0101 0100
160 - 1010 0000
53 - 0011 0101
137 - 1000 1001
What are the two ways negative numbers are represented in binary
- Sign magnitude
- Two’s complement
How do you convert a Binary Number into a negative number using Sign Magnitude
- A leading 1 is added for a negative number
- A leading 0 is added for a positive number
Convert the decimal number -21 into a two’s complement binary number (Method)
128 64 32 16 8 4 2 1
0 0 0 1 0 1 0 1
One’s Complement (Flip) - 1 1 1 0 1 0 1 0
Two’s Complement (+1) - 1 1 1 0 1 0 1 1
Answer = 1110 1011
Subtract the binary number
0000 1111 from 1001 0100
Two’s Complement 0000 1111 = 1111 0001
Add the two numbers - 1001 0100
+ 1111 0001
=[1] 1000 0101
Answer = 1000 0101
Compare Decimal and Hexadecimal Numbers
Convert the binary 1111 0101 into hexadecimal
Split into 4 - 1111 0101
Work out the value of both parts - 1111 = 15 0101 = 5
Convert into Hexadecimal - 15 = F 5 = 5
Answer = F5
What is the Mantissa and Exponent of 123
Mantissa - 1.23
Exponent - x 10^2
Convert the decimal number 50 into a two complement floating point binary number using a 8-bit Mantissa and a 4-bit Exponent
Write in Binary - 1 1 0 0 1 0
Normalise the number (reposition decimal point in front of first 1) - 0.110010 x 2^6
Answer =
Mantissa = 01100100 Exponent = 0110
Convert the decimal number 0.375 into a two’s complement floating point binary number using a 4-bit Mantissa and 4-bit Exponent
Write in Binary - 0 . 0 1 1
Normalise the number - 0. 1 1 x 2^-1
Answer =
Mantisaa = 0110 Exponent = 1111
Convert the decimal number -21 into a two’s complement floating point number using a 8-bit Mantissa and 4-bit Exponent
Write in Binary - 1 0 1 0 1
Normalise the number - 0. 1 0 1 0 1 0 0 x 2^5
Two’s Complement - 1. 0 1 0 1 1 0 0
Answer =
Mantissa = 1010 1100 Exponent = 0101
Convert the floating point number 011100 001 into decimal
Convert Exponent into Decimal = 1
Truncate (opposite of Normalise) the Mantissa = 0. 1 1 1
Move point back 1 space = 1. 1 1
Convert into Decimal - 1.75
Answer = 1.75
How do you add floating point numbers
- To add floating point binary numbers, their exponents need to be the same
- Then add the mantissas
- Finally, normalise the result if required
How do you subtract floating point numbers
- Involves converting to two’s complement and adding
- The exponents must be the same
- Use binary addition on the mantissas
- Normalise the result if required
What is a Logical Shift
- A logical shift involves moving all of the bits in a binary number a specified number of places to the right or to the left
- Can be thought of as adding a number of leading or trailing zeros
- The result is a multiplication (or division if shifting right) by two to the power of the number of places shifted
- A logical shift left by one place has the effect of doubling the initial number
What happens when you mask a binary number
When you use binary numbers by combining them with a logic gate