141-data-representation Flashcards
Data Types
- Forms of data stored and used in computer programs.
- Different data types take up different amounts of memory.
- The correct data type should be used to optimize program performance.
Main data types include: integer, real/float, boolean, character, and string
- Integer - whole numbers without a fractional part
- Real - numbers that may or may not have a fractional part (Float is a subtype of real numbers and represents a number with a floating decimal point)
- Character - single symbol used by a computer, including alphanumeric
- String - collection of characters, used for storing text and phone numbers
- Boolean - only two truth values (true or false), associated with logic and Boolean algebra.
Primitive data type:
- Basic data type provided by programming language
- Foundational building block for more complex data types
- Number, type, and name of primitive data types vary between programming languages
- All programming languages support primitive data types
Casting data types
converting one data type to another.
Why is data stored in computers in a binary format?
- circuits only need to check for two states: electricity flowing or not flowing, on or off, and 1 and 0
- less precision is required to detect one of two states e.g during data transfer
-compatibility with existing systems - simpler to build electronic devices/electrical components that only use two states
- additional states would make the components more difficult to build and more prone to error.
- bit patterns used to represent instructions and various forms of data e.g character sets, images
Bit
binary digit that can have two values: 0 or 1.
Overflow Error
- number cant fit into one byte/whatever and is too big for the register
- extra carry/bit
- results in a loss of accuracy as bits on the left are removed.
Hexadecimal
- base 16, made up of 4 bits per hex digit.
- 1 hexadecimal = 1 nibble.
- used in defining colours in graphics software, representing MAC addresses and memory addresses, checksums.
- straightforward to convert between binary and it, shorter to remember, quicker to enter, less susceptible to error, easier/quicker to communicate/write/read with
Sign and Magnitude
- First number represents sign. 1 is negative and 0 is positive.
- Largest positive number in an 8-bit binary using sign and magnitude is +127.
- Can represent negative numbers from -1 to -127.
- Simple and easy to understand. Allows for straightforward representation of both positive and negative numbers.
- Two representations of zero (+0 and -0). More complex when doing arithmetic involving negative numbers. Waste of one bit
- Used when there is no need to perform complex arithmetic with negative numbers, and simplicity is more important.
One’s Complement
- Easy to implement. Same magnitude bits are added easily.
- Has two representations of 0 (-0 or 0). there cannot be a negative zero, so this ambiguity can cause problems in some computations and when with all bits set as 1 or 0 . complications with rounding, overflow and precision errors
- Complexity: requires additional logic and operations to handle negative numbers, makes programming more complex and time-consuming.
- Used in some computer architectures, but generally not preferred over two’s complement.
ones complement method
- Flip all the bits of a negative binary number and result is the positive version, and vice versa.
E.g 0101 is 5, 1010 is –5.
Two’s complement
- Only one representation of zero. Simpler and more efficient for arithmetic operations on negative numbers. Simplifies implementation.
- most significant bit as a negative value number
- hardware support for negation. complement operation is a bit-wise operation, faster than division/multiplication, etc.
- A negative number has one more negative value than a positive number. e.g -128 to 64 for 8 bits
- Almost universally used in modern computer systems.
twos complement method
First number is a negative number. E.g 1110 would be -8 + 4 + 2 = -2.
Adding 1’s to the number front will not change the value.
To change from positive to negative, flip all the bits and add 1 (binary version so 0000 0001).
Positive numbers always start with a 0, while negative numbers always start with a 1.
fixed-point binary
- stores fractions with a fixed position of the point on the number line: fixed number of bits for integer and fractional parts, with a fixed decimal point position and scaling factor.
- range of numbers that can be stored is limited due to some positions being used for the fractional part.
- e.g. 6-bit fixed-point number with 8 fractional bits might represent the value 1.5 as 0000 0001 0100 0000, first 8 bits’ the integer part and the remaining 8 bits’ the fractional part.
- simpler but less flexible than floating-point. Do not need to be normalized, unlike floating-point numbers.
normalisation
- Representing a floating-point number in a standard form.
- involves adjusting it to start with 01 for positive or 10 for negative
- to ensure precision in a given number of bits and that there is only one way of representing any given number, which is important for consistency and storing numbers to the highest possible degree of accuracy
- Necessary for correct arithmetic operations and comparisons between floating-point numbers.