ScholarQuill logoScholarQuillUniversity Notes
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
Study Tools
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
Contact
ScholarQuill logo
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
ScholarQuill logoScholarQuillUniversity Notes
Study PortalDC-221Integer Representation…
Ctrl + K
Login
Explore
Search
Semester
Papers
CGPA
    DC-221

    Computer Organization and Assembly Language

    Progress0 / 35 done
    Topics35
    1Introduction to Computer Systems2Information is Bits + Context3Programs are Translated by Other Programs4Understanding Compilation Systems5Processors Read and Interpret Instructions6Caches Matter7Storage Devices Form a Hierarchy8The Operating System Manages the Hardware9Systems Communicate Using Networks10Representing and Manipulating Information11Information Storage12Integer Representations13Integer Arithmetic14Floating Point15Machine-Level Representation of Programs16A Historical Perspective17Program Encodings18Data Formats19Accessing Information20Arithmetic and Logical Operations21Control22Procedures23Array Allocation and Access24Heterogeneous Data Structures25Understanding Pointers26Using the GDB Debugger27Out-of-Bounds Memory References and Buffer Overflow
    28Extending IA-32 to 64 Bits29Machine-Level Representations of Floating-Point Programs30Processor Architecture31The Y86 Instruction Set Architecture32Logic Design and the Hardware Control Language (HCL)33Sequential Y86 Implementations34General Principles of Pipelining35Pipelined Y86 Implementations
    5 min read
    Topic 12 of 35
    Topic Study Note Illustration
    12

    Integer Representations

    In computer systems, numbers are represented using binary digits (bits). Since computers operate on binary logic (0s and 1s), different schemes are used to represent integers efficiently....

    Integer Representations in Computer Organization and Assembly Language

    In computer systems, numbers are represented using binary digits (bits). Since computers operate on binary logic (0s and 1s), different schemes are used to represent integers efficiently. The main integer representation methods are:

    1. Unsigned Representation
    2. Signed Magnitude Representation
    3. Two’s Complement Representation
    4. One’s Complement Representation
    5. Excess (or Bias) Representation

    1. Unsigned Integer Representation

    • Uses only positive numbers, with all bits representing the magnitude.
    • A binary number with nnn bits can represent values from 0 to 2n−12^n - 12n−1.
    • Example (8-bit representation):
      • 000000002=000000000_2 = 0000000002​=0
      • 000000012=100000001_2 = 1000000012​=1
      • 111111112=25511111111_2 = 255111111112​=255 (Max value for 8 bits)

    🔹 Use case: Useful in scenarios where negative numbers are not needed (e.g., memory addresses).


    2. Signed Magnitude Representation

    • The most significant bit (MSB) is the sign bit (0 for positive, 1 for negative), and the remaining bits represent the magnitude.
    • Range: −(2n−1−1)- (2^{n-1} - 1)−(2n−1−1) to +(2n−1−1)+(2^{n-1} - 1)+(2n−1−1)
    • Example (8-bit representation):
      • 000001012=+500000101_2 = +5000001012​=+5
      • 100001012=−510000101_2 = -5100001012​=−5

    🔹 Disadvantage:

    • Has two representations for zero: 000000002=+000000000_2 = +0000000002​=+0 and 100000002=−010000000_2 = -0100000002​=−0, leading to inefficiency.
    • Arithmetic operations (addition, subtraction) require additional logic.

    3. Two’s Complement Representation (Most Common for Signed Integers)

    • The MSB is the sign bit (0 for positive, 1 for negative), but negative numbers are stored as the two’s complement of their magnitude.

    • To get the two’s complement of a number:

      1. Invert all bits (one’s complement).
      2. Add 1 to the result.
    • Advantages:

      • Eliminates the problem of two representations for zero.
      • Makes addition and subtraction simpler.
      • Allows seamless wraparound in arithmetic operations.
    • Range for an nnn-bit system:

      • −2n−1-2^{n-1}−2n−1 to 2n−1−12^{n-1} - 12n−1−1
    • Example (8-bit representation of -5):

      • 000001012=+500000101_2 = +5000001012​=+5
      • Invert bits: 11111010211111010_2111110102​
      • Add 1: 111110112=−511111011_2 = -5111110112​=−5
    • Example values in 8-bit two’s complement:

      • 011111112=12701111111_2 = 127011111112​=127
      • 100000002=−12810000000_2 = -128100000002​=−128 (smallest number)
      • 111111112=−111111111_2 = -1111111112​=−1

    🔹 Why is it widely used?

    • Efficient for arithmetic operations.
    • Allows CPU to use the same hardware circuits for addition and subtraction.

    4. One’s Complement Representation

    • Similar to two’s complement but without adding 1.

    • To represent a negative number, invert all bits.

    • Example (8-bit representation of -5):

      • 000001012=+500000101_2 = +5000001012​=+5
      • Invert bits: 11111010211111010_2111110102​ (One’s complement of -5)
    • Problems:

      • Two representations of zero: 000000002=+000000000_2 = +0000000002​=+0 and 111111112=−011111111_2 = -0111111112​=−0.
      • Arithmetic operations require handling of carry bits.

    🔹 Not commonly used due to inefficiency in arithmetic operations.


    5. Excess (Bias) Representation

    • Used primarily for floating-point numbers.

    • A fixed bias is subtracted from the stored value to get the actual value.

    • Example (Excess-127 in 8-bit representation):

      • Bias = 127
      • Stored value = Actual value + Bias
      • If actual exponent = 5, stored = 5+127=1325 + 127 = 1325+127=132 (Binary: 10000100210000100_2100001002​).

    🔹 Used in IEEE 754 Floating-Point Representation.


    Comparison of Representations

    Representation Range (for 8-bit) Zero Representations Arithmetic Efficiency
    Unsigned 0 to 255 1 Simple
    Signed Magnitude -127 to 127 2 Complex
    Two’s Complement -128 to 127 1 Efficient
    One’s Complement -127 to 127 2 Less Efficient
    Excess/Bias Floating Point 1 Used in FP

    Conclusion

    • Two’s complement is the most widely used method for representing integers in modern computers due to its arithmetic efficiency and simplicity.
    • Unsigned representation is useful where negative numbers are not needed.
    • One’s complement and signed magnitude are mostly historical and not used in modern CPUs.
    • Excess representation is primarily used for floating-point arithmetic.
    ← Previous topic 11
    Information Storage
    Next topic 13 →
    Integer Arithmetic

    Past Papers

    Open this section to view and download past papers

    Click on Show Past Papers to load available exam papers.

    Reading Progress
    0%
    5mremaining
    821words
    Beginnerlevel
    On This Page

    No headings found

    Study Toolkit

    Subject Portal

    Computer Organization and Assembly Language