Back to 课程

Computer-Science-A-level-Ocr

0% Complete
0/0 Steps
  1. 3-3-networks
    8 主题
  2. 3-2-databases
    7 主题
  3. 3-1-compression-encryption-and-hashing
    4 主题
  4. 2-5-object-oriented-languages
    7 主题
  5. 2-4-types-of-programming-language
    4 主题
  6. 2-3-software-development
    5 主题
  7. 2-2-applications-generation
    6 主题
  8. 2-1-systems-software
    8 主题
  9. 1-3-input-output-and-storage
    2 主题
  10. 1-2-types-of-processor
    3 主题
  11. 1-1-structure-and-function-of-the-processor
    1 主题
  12. structuring-your-responses
    3 主题
  13. the-exam-papers
    2 主题
  14. 8-2-algorithms-for-the-main-data-structures
    4 主题
  15. 8-1-algorithms
    10 主题
  16. 7-2-computational-methods
    11 主题
  17. 7-1-programming-techniques
    14 主题
  18. 6-5-thinking-concurrently
    2 主题
  19. 6-4-thinking-logically
    2 主题
  20. 6-3-thinking-procedurally
    3 主题
  21. 6-2-thinking-ahead
    1 主题
  22. 6-1-thinking-abstractly
    3 主题
  23. 5-2-moral-and-ethical-issues
    9 主题
  24. 5-1-computing-related-legislation
    4 主题
  25. 4-3-boolean-algebra
    5 主题
  26. 4-2-data-structures
    10 主题
  27. 4-1-data-types
    9 主题
  28. 3-4-web-technologies
    16 主题
课 Progress
0% Complete

Signed Binary Numbers

What are signed binary numbers?

  • A binary number can be signed or unsigned: 

    • Unsigned – used to represent positive binary numbers

    • Signed – used to represent both positive and negative binary numbers

  • We can use signed binary numbers to represent negative numbers using methods such as:

    • Sign & magnitude

    • Two’s complement

  • Both of these methods use the Most Significant Bit (MSB) to represent whether the number is negative or positive:

    • If the MSB is 0, the number is positive

    • If the MSB is 1, the number is negative

Sign & Magnitude

  • Sign & magnitude binary numbers contain a:

    • Sign – This is when the MSB is used to represent whether the number is negative (1) or positive (0)

    • Magnitude – This is used to describe the rest of the bits after the MSB

sign-and-magnitude

Representing negative binary numbers using sign & magnitude

Binary to denary example

  • To convert a sign & magnitude binary number to denary, you need to:

    • Convert the number as normal from binary to denary (as described in Positive Binary number: Binary to Denary)

    • Apply the MSB at the end of the calculation

      • If the MSB is 1, the number is negative

      • If the MSB is 0, the number is positive

msb-binary-to-decimal

Converting sign & magnitude binary numbers to denary

Denary to binary example

  • To convert a denary number to a sign & magnitude binary number, you need to:

    • Identify whether the number is positive or negative

    • Convert the number to binary as normal (as described in Positive Binary Numbers: Denary to Binary)

    • If the number is negative, change the MSB to

MSB

64

32

16

8

4

2

1

1

1

0

0

0

1

1

1

  • 64 + 4 + 2 + 1 = 71

  • Apply a sign of 1 to make -71

  • Therefore the denary number -71 in binary is 11000111 

A consequence of using a sign bit

  • The MSB purpose changes from representing a value to representing positive or negative

  • Losing the MSB halves the maximum size of the number that can be stored

  • However, as a benefit it makes it possible to represent negative numbers

sign-magnitude-number-system

Sign & magnitude number system

Worked Example

Convert the 8-bit sign and magnitude binary number 10001011 to denary.

How to answer this question:

  • Identify the sign bit: The MSB is 1, so the number is negative

  • Isolate the magnitude: We are left with 0001011 by removing the sign bit

  • Convert to denary: The binary number 0001011 converts to 11 in denary

  • Apply the sign: The MSB was 1, so the number is -11 in denary

Answer:

Answer that gets full marks

10001011 converts to -11 in denary

Two’s Complement

  • Two’s complement is a different method for representing negative binary numbers

  • Calculations on two’s complement numbers are less computationally intensive

Method

  1. Start with the absolute value of the number, in this case 12

  2. Invert the bits so that all of the 1’s become 0’s and all of the 0’s become 1’s

  3. Add 1

Diagram showing conversion of denary 12 to binary, inversion, adding one to form two's complement, resulting in negative offset -12 in binary.

Representing two’s complement binary numbers

  • The purpose of the MSB has changed; it now represents the negative starting point of the number, and the rest of the bits are used to count upwards from that number

  • Using the binary number from the image above:

    • Begin counting at -16

    • Add 4 to make -12

  • Two’s complement has a similar consequence to sign and magnitude as the maximum value of an 8-bit value is halved

Denary to binary example

  • To convert the denary number -24 to a two’s complement binary number, you need to:

    • Convert the number to binary

-128

64

32

16

8

4

2

1

0

0

0

1

1

0

0

0

  • Invert the bits

-128

64

32

16

8

4

2

1

1

1

1

0

0

1

1

1

  • Add 1 to the number

<td class=”border border-dark ContentBlock_tableCell__N2pb_” colspan=”1″ rowsp

-128

64

32

16

8

4

2

1

1

1

1

Responses

您的邮箱地址不会被公开。 必填项已用 * 标注