ScholarQuill logoScholarQuillUniversity Notes
  • Notes
  • Past Papers
  • Blogs
  • Todo
Login
ScholarQuill logoScholarQuillUniversity Notes
Login
NotesPast PapersBlogsTodo
More
SubjectsDiscussionCGPA CalculatorGPA CalculatorStudent PortalCourse Outline
About
About usPrivacy PolicyReportContact
Notes
Past Papers
Blogs
Todo
Analytics
    Current Subject
    🧩
    Computer Organization and Assembly Language
    DC-221
    Progress0 / 35 topics
    Topics
    1. Introduction to Computer Systems2. Information is Bits + Context3. Programs are Translated by Other Programs4. Understanding Compilation Systems5. Processors Read and Interpret Instructions6. Caches Matter7. Storage Devices Form a Hierarchy8. The Operating System Manages the Hardware9. Systems Communicate Using Networks10. Representing and Manipulating Information11. Information Storage12. Integer Representations13. Integer Arithmetic14. Floating Point15. Machine-Level Representation of Programs16. A Historical Perspective17. Program Encodings18. Data Formats19. Accessing Information20. Arithmetic and Logical Operations21. Control22. Procedures23. Array Allocation and Access24. Heterogeneous Data Structures25. Understanding Pointers26. Using the GDB Debugger27. Out-of-Bounds Memory References and Buffer Overflow28. x86-64: Extending IA-32 to 64 Bits29. Machine-Level Representations of Floating-Point Programs30. Processor Architecture31. The Y86 Instruction Set Architecture32. Logic Design and the Hardware Control Language (HCL)33. Sequential Y86 Implementations34. General Principles of Pipelining35. Pipelined Y86 Implementations
    DC-221›Integer Representations
    Computer Organization and Assembly LanguageTopic 12 of 35

    Integer Representations

    5 minread
    821words
    Beginnerlevel

    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 load past papers

    Click on Show Past Papers to see past papers.
    On This Page
      Reading Stats
      Est. reading time5 min
      Word count821
      Code examples0
      DifficultyBeginner