Data types Flashcards
What does an AND operator do? (Mask)
AND operator is used to clear a particular bit, leaves the other bits unchanged
AND 1 and 0 meaning
Use 1 to keep the number the same
Use 0 to change the number
What does an OR operator do? (Mask)
OR operator used to set a particular bit, leaves the other bits unchanged
OR 0 and 1 meaning
0 the keep the number the same
1 to change/set the number
What does a XOR operator do? (Mask)
XOR operator used to toggle a particular bit, leaves the other bits unchanged
XOR 0 and 1 meaning
1 toggles the number
0 keeps the number the same
And truth table
0+0=0
0+1=0
1+0=0
1+1=1
OR truth table
0+0=0
0+1=1
1+0=1
1+1=1
XOR truth table
0+0=0
0+1=1
1+0=1
1+1=0
What mask do you use to make lowercase
Apply OR mask
0010 0000
What mask do you use to make uppercase
AND mask
1101 1111
Normalised floating point rules
Mantissa always starts with:
01 for positive numbers
or
10 for negative numbers
Why should you use the correct data type
Different data types take up different amounts of memory. To optimise program performance it’s important to use the correct data type where possible
What are the different data types
Integer
Real/float
Boolean
Character
String
Define primitive data type
Any basic data type provided by a language as a foundational building block
Define composite data type
Most languages allow more complex data types to be constructed from primitive data types
Define integer
Integer data type represents any positive or negative whole nunber
Define real
The real data type represents any positive or negative number including decimals or fractions
Define character
The character data type represents a single character (symbol or letter)
Define string
The string data type represents a collection of characters (not limited to letters)
Define Boolean
The Boolean data type can be used to represent one of two truth values associated with logic
Define casting
A way to convert one data type to another
What is sign and magnitude
A way of representing negative numbers
What does a positive number start with (S+M)
Positive numbers start with a 0
What does a negative number start with (S+M)
A negative number starts with a 1
What does the most significant bit represent (S+M)
It becomes a sign bit- so it no longer holds a value
What is the largest positive and negative number: (S+M)
Positive: 127
0111 1111
Negative: -127
1111 1111
Disadvantages of S+M
There is +0 and -0
Two different types of data that are being represented with one number
Not useful for arithmetic
Advantage of S+M
Easy for humans to do
What do positive numbers start with (twos complement)
Always start with 0
What do negative numbers start with (twos complement)
Always start with a 1
What does the most significant bit represent (twos complement)
Represents a negative number
Positive binary number into negative twos complement method
- Write out the positive version of the number
- Starting from the right most bit copy each of the digits exactly as they appear up to and including the first 1
- From this point swap every 1 for a 0 and every 0 for a 1
Advantage of twos complement
It is better for arithmetic
Define character set
A defined list of characters recognised by the computer hardware and software, with each character being represented by a single nunber
ASCII mean
American Standard Code for Information Interchange
How many ASCII bits
7
UNICODE bits
24 bit character set