Chapter 6 - Data Types Flashcards
Definition of Data Type
defines a collection of data values and a set of pre-defined operations on those values
Definition of descriptor
the collection of the attributes of a variable
Definition of primitive data type
data types that are not defined in terms of other types
Why do primitive data types need very little non-hardware support for implementation?
These types are merely reflections of the hardware itself
What does it mean to be “a reflection of the hardware”?
that the entity is represented by some physical hardware mechanism
The 4 types of integer sizes in Java
byte
short = 2 bytes
int = 4 bytes
long = 8 bytes
(all integers in Java are signed)
Why are integers a reflection of the hardware?
The maximum value that can be represented, depends on the number of physical mechanisms used to define each bit
3 Different hardware implementations for signed integers
Dumb way = the most significant bit (the left-most one) determines the sign of the number. 1 implies a negative number and 0 implies a positive number
One’s Complement = The negation of a given number is obtained by flipping all the bits of that number.
Two’s Complement = the negation of a number is obtained by flipping all the bits and then adding one
Definition of Floating-point number data type
a primitive data type modeling real numbers (not just integers)
What is the size of a regular floating point number? How are the bits distributed?
4 bytes or 32 bits
sign bit = 1 bit
exponent = 8 bits
fraction or mantissa = 23 bits
Definition of double data type
A double precision floating point number
What is the size of a double data type? how are the bits distributed?
8 bytes or 64 bits
sign bit = 1 bit
exponent = 8 bits
fraction or mantissa = 53 bits
What is the floating point number exponent value and how is it represented?
The exponent refers to the exponent value of the floating point number in scientific notation
Simply add 127 to the value of the exponent and express that result in binary (doesn’t change for negative exponents).
ex) exponent = 5, result = 5 + 127 = 132, bin(132) = 1000010 (27 + 22 = 132)
exponent of 5 = 1000010
What is the floating point number fraction value and how is it represented?
Each digit after the decimal point represents a negative power of 2. Decimal values are approximated by combining these negative powers of 2
- 1 = 2**-1 = 0.5 (in decimal)
- 001 = 2**-2 = 0.25
- 0001 = 2**-3 = 0.125
The number in front of the decimal point is expressed normally in binary
How to express the sign of a floating point number
The sign bit represents the sign of the mantissa!
1 = negative 0 = positive
Definition of decimal data type
store a fixed number of decimal digits with the decimal point at a fixed position in the value
What common PLs have decimal data types?
COBOL
C#
F#
What is the main advantage of using decimal numbers instead of floating point numbers?
Decimal numbers are able to store decimal values exactly within a limited range
Floating point numbers can only approximate decimal values (remember that they approximate decimal values by using combinations of negative powers of 2, which makes it impossible to precisely store certain values)
What are the disadvantages of using decimal numbers instead of floating point numbers?
for decimal numbers:
- the range of values that can be expressed is limited
- their representation in memory is slightly wasteful
Definition of a nibble
4 bits or half of a byte
What does BCD stand for? What does it mean?
binary coded decimal
Meaning that each digit (0-9) and the sign(+/-), is represented by a nibble (4 bits)
How are the digits of a decimal number represented in binary?
The leftmost digit of the decimal number is the leftmost nibble in the binary representation
The digits 0-9 are represented by their normal 4-bit binary values (ex. 9 = 1001)
How is the sign of a decimal number represented in binary?
The sign is the rightmost nibble
+ sign represented by: 1100
- sign represented by: 1101
Definition of boolean data type
a data type with 2 allowed values true or false
What is the size of a normal boolean data type?
1 byte
It can theoretically be represented by 1 bit, however, this data type is typically stored in the smallest efficiently addressable cell of memory (typically 1 byte)
Which PL was first to include the boolean data type?
ALGOL 60
How is character data represented in memory?
with some numeric coding
ASCII vs Unicode
ASCII - an 8-bit numeric coding for characters. Can represent 128 characters (0-127)
Unicode - a 16-bit numeric coding for characters. The first 128 characters are identical to ASCII
Definition of character string type
a data type consisting of sequences of characters
Two most prominent representations of Strings
implemented as a (hardware) primitive type or as an array of single characters
2 main design issues pertaining to Strings
1) should it be implemented as some kind of character array or as a primitive type?
2) should they have static or dynamic length