In-Depth Notes on Binary Numbers and Representation
Binary Numbers
- Binary System: Uses two symbols, 0 and 1, to represent values.
- Each digit in a binary number represents a power of 2 (e.g., 2^0, 2^1, etc.).
Binary-to-Decimal Conversion
- Process: Multiply each binary digit by its weight (power of 2) and sum the results.
- Example: Binary 1011 converts to decimal as follows:
- (1 × 2^3) + (0 × 2^2) + (1 × 2^1) + (1 × 2^0) = 8 + 0 + 2 + 1 = 11.
Decimal-to-Binary Conversion
Whole Numbers: Divide by 2, track the remainder, and reverse the order of results once the quotient is 0.
Example: For 11, 11 ÷ 2 = 5, remainder 1; 5 ÷ 2 = 2, remainder 1; 2 ÷ 2 = 1, remainder 0; 1 ÷ 2 = 0, remainder 1. Result: 1011.
Fractions: Multiply by 2, track the integer part, stop when the result is 0.
Example: 0.625 × 2 = 1.25 (1), 0.25 × 2 = 0.5 (0), 0.5 × 2 = 1.0 (1). Result: 0.101.
Hexadecimal Numbers
- Hexadecimal System: Base-16, uses digits 0-9 and letters A-F to represent values.
- Conversion: Group binary digits in sets of 4 (starting from least significant bit).
- Example: Convert 101100 to Hexadecimal:
- Group: 0010 1100 = 2C in Hexadecimal.
Octal Numbers
- Octal System: Base-8, uses digits 0-7.
- Conversion: Group binary digits in sets of 3.
- Example: Binary 101100110 converts to octal as: 001 011 001 110 = 2 3 1 6.
Integer Representation
- Unsigned Integers: Non-negative values, example range for 8-bit: 0 to 255.
- Signed Integers: Can represent both positive and negative values using:
- Sign-and-Magnitude: Most significant bit (MSB) indicates sign. Example: +0 (00000000), -0 (10000000).
- One's Complement: Inverts bits. Example: +117 is 01110101, -117 is 10001010.
- Two's Complement: Inverts bits and adds 1 for negative representation, only one representation for zero.
Floating-Point Representation
- Fixed-Point Representation: Represents real numbers but limited by its fixed number of digits for integers and fractions.
- Floating-Point Notation: Express numbers in scientific form. IEEE 754 standard defines the structure for this representation.
- Single Precision: 1 sign bit, 8 bits exponent, 23 bits mantissa.
- Double Precision: 1 sign bit, 11 bits exponent, 52 bits mantissa.
Logical Operations
- Bitwise Operations: Perform logical operations on bits, applicable to all integer types.
- AND (&): 1 if both bits are 1.
- OR (|): 1 if either bit is 1.
- XOR (^): 1 if bits are different.
- NOT (~): Inverts bits.
- Shift Left (<<): Multiplies by 2.
- Shift Right (>>): Divides by 2.
Overflow and Error Handling
- Overflow: Occurs if the result exceeds the range of the number representation; for example, adding two large positive numbers may yield a negative result in two's complement representation.
- Solution: Adding an extra bit may allow correct representation of results.
Summary
- Comprehensive understanding of Binary, Decimal, Hexadecimal, and Octal systems and conversions.
- Insight into Integer representations, both unsigned and signed.
- Clarity on Floating-Point representations per IEEE 754 standards.
- Proficiency in performing Logical Operations and managing overflow conditions in number representations.