Data Representation Notes
Table of Contents
- Introduction to Data Representation
- Number Systems
- 2.1 Binary System
- 2.2 Decimal (Denary) System
- 2.3 Hexadecimal System
- Conversions Between Number Systems
- 3.1 Converting Denary to Binary
- 3.2 Converting Denary to Hexadecimal
- 3.3 Converting Hexadecimal to Binary
- Binary Operations
- 4.1 Binary Addition
- 4.2 Understanding Overflow in Binary Addition
- Logical Shifts
- 5.1 Logical Left Shifts
- 5.2 Logical Right Shifts
- Two’s Complement Representation
- 6.1 Representing Positive and Negative Integers
- 6.2 Conversion between Two’s Complement and Denary
- Applications of Hexadecimal
- Conclusion
1. Introduction to Data Representation
Computers use data representation to store and process various types of data, such as numbers, characters, and images. Data is ultimately represented in binary form because computers operate using electronic circuits that can only be in two states: on (1) or off (0).
2. Number Systems
2.1 Binary System
- Base 2: The binary system uses two digits, 0 and 1. Each digit represents a power of 2, starting from the rightmost digit, which is
- Representation of Data: All forms of data, including numbers, text, and images, must be converted into binary for processing by computers.
2.2 Decimal (Denary) System
- Base 10: The decimal system uses ten digits (0-9). Each digit represents a power of 10.
- Example: The decimal number 345 can be expressed as:
2.3 Hexadecimal System
- Base 16: The hexadecimal system uses sixteen digits (0-9 and A-F, where A=10, B=11, C=12, D=13, E=14, F=15).
- Easier Representation: Hexadecimal is often used in programming and digital electronics because it provides a more compact representation of binary data. For example, the binary number
11111111
can be represented asFF
in hexadecimal.
3. Conversions Between Number Systems
3.1 Converting Denary to Binary
- Divide the denary number by 2.
- Record the remainder.
- Repeat until the quotient is 0.
- The binary equivalent is read from bottom to top.
3.2 Converting Denary to Hexadecimal
- Divide the denary number by 16.
- Record the remainder.
- Repeat until the quotient is 0.
- The hexadecimal equivalent is read from bottom to top.
3.3 Converting Hexadecimal to Binary
Each hexadecimal digit can be converted to a 4-bit binary equivalent. For example:
- A = 1010
- B = 1011
4. Binary Operations
4.1 Binary Addition
- Adding Binary Numbers: Similar to decimal addition, but with carrying over when the sum exceeds 1.
- Example:
4.2 Understanding Overflow in Binary Addition
- Overflow Error: Occurs when the result of a binary addition exceeds the maximum value that can be stored in the given number of bits.
- For an 8-bit register, the maximum value is 255 (11111111 in binary). An overflow occurs if the result exceeds this limit.
5. Logical Shifts
5.1 Logical Left Shifts
- Operation: Moves all bits to the left and fills the rightmost bits with zeros.
- Effect: Multiplies the binary number by 2 for each shift.
- Example:
- Original:
00011010
(26 in decimal) - After one left shift:
00110100
(52 in decimal)
- Original:
5.2 Logical Right Shifts
- Operation: Moves all bits to the right and fills the leftmost bits with zeros.
- Effect: Divides the binary number by 2 for each shift.
- Example:
- Original:
00011010
(26 in decimal) - After one right shift:
00001101
(13 in decimal)
- Original:
6. Two’s Complement Representation
6.1 Representing Positive and Negative Integers
- Positive Integers: Represented the same as in standard binary.
- Negative Integers: To find the two’s complement:
- Invert all bits (0 becomes 1 and vice versa).
- Add 1 to the least significant bit (LSB).
6.2 Conversion between Two’s Complement and Denary
- Positive to Two’s Complement: Same as binary.
- Negative to Two’s Complement: Follow the steps above to convert to binary, then to denary.
7. Applications of Hexadecimal
- Programming: Used for memory addresses and color codes in web design (e.g.,
#FF5733
). - Debugging: Easier to read than long binary sequences.
8. Conclusion
Understanding data representation is crucial in computer science, as it lays the foundation for how data is processed, stored, and manipulated within a computer system. Mastery of number systems, conversions, and binary operations enhances a candidate's ability to work with computer data efficiently.
0 Comments