1.4.1 - Data Types Flashcards
Why is it important to make sure data is stored with the right type?
So the right operations can be performed on it.
What is an integer?
An integer is a whole number. Integers include zero and negative numbers, they just can’t have a fractional part. Integers are useful for counting things.
What is a real number?
Real numbers are positive or negative numbers which can, but do not necessarily, have a fractional part. Reals are useful for measuring things. All integers are real numbers. Real numbers can also be represented using floating point, which is explained later.
What is a character?
A character is a single symbol used by a computer. These include the letters A to Z, the numbers 0 to 9 and hundreds of symbols like %, £ and :)
What is a string?
A string is a collection of characters. While a string can be used to store a single character, they can also be used to store many characters in succession.
Strings are useful for storing text and phone numbers which start with a 0, which numeric data types like integers would cut off.
What is a Boolean?
Named after the mathematician George Boole (hence written with a capital B), values taken by a Boolean data type are restricted to True and False. Booleans are useful for recording data that can only take two values.
What does base 2 mean?
Each step in place represents a value of two times the previous place.
What is a single binary digit?
A single binary digit is called a bit, and eight binary digits can be combined to form a byte.
Entertainingly, half a byte (four bits) is called a nybble.
What is the least significant bit of a binary number?
The one furthest to the right.
What is sign magnitude?
The most basic way to represent negative numbers in binary. The equivalent of adding a + or - sign, with a leading 1 for a negative and leading 0 for a positive.
What is two’s complement?
A method of representing negative numbers in binary which makes the most significant bit negative.
How to convert to two’s complement.
Flip all of the bits in the positive version of a binary number and add one.
Why is two’s complement good?
It makes subtraction in binary easy. You simply add the twos complement version of a number.
How to convert from hexadecimal to binary?
Convert each hex digit to a decimal, then binary nybble. Then, combine the nybbles.
How to work out floating point binary.
Mantissa starts with decimal point after most significant bit. Moves places to the right, depending on what the exponent is in decimal.
How to normalise a floating point number?
Split into mantissa and exponent.
Adjust so it starts 01 or 10
Add the exponent to represent number of shifts right to get to original.
How to add/subtract floating point numbers?
Adjust for same exponent.
Carry out binary addition/two’s complement subtraction.
Normalise result.
What do shifts do in binary?
They move all of the bits a specified number to the left or right, which essentially multiplies or divides the original number by 2^n.
How do we apply a mask to binary numbers?
Combine them with a logic gate.
What is ASCII?
ASCII was the leading character set before Unicode. It uses 7 bits to represent 128 characters. There are codes for numbers and symbols too.
When did ASCII encounter problems?
When computers needed to represent other languages with different characters.
What does Unicode do?
Unicode solves the problem of ASCII’s limited character set. Unicode uses a varying number of bits allowing for over 1 million different characters, many of which have yet to be allocated. Because of this, Unicode has enough capacity to represent a wealth of different languages, symbols and emoji.