Signed number representations

Signed magnitude, one's complement, two's complement

18 flashcards · Computer Science · by lakesare

  1. Name 4 ways to store signed numbers in memory.

    signed magnitude: reserve most significant bit - to signify positive (0); or negative (1) one's complement: if number is negative - signed magnitude, and flip all the remaining bits two's complement: if number is negative - one's complement, and add 1. excess-n (== offset binary, bias representation) notation: take a number, and add n to it. Express result in binary.

  2. Why is signed magnitude and one's complement usually ditched for two's complement?

    If we use signed magnitude-stored numbers and try to + them - we'll get a wrong result. One's complement works nicely with addition, but: sometimes results in 1000 (negative 0). returns results smaller than needed by 1: 5 + (-3) = 0101 + 1100 = 10001 = 1 (should be 2) One of the big problems that occur when using One's complement is that the number zero has two representations, either all 0's or all 1's. Using 4 digits both 0000 and 1111 represent zero. This problem can be solved by using Two's…

  3. What range of signed (two's complement) VS unsigned integers can we represent in 1 byte?

    Unsigned integers: from 0 to 28-1 (= from 0 to 255) (we need to minus 1 because 2^8 already includes 0, and amount of numbers that can be stored in 8 bits is already 28) Two's complement: from -28-1 to 28-1 - 1 (= from -128 to 127) (we need to 8-1 because the left-most bit is busy with a sign) For example, an 8-bit unsigned number can represent the values 0 to 255 (11111111).However a two's complement 8-bit number can only represent positive integers from 0 to 127 (01111111), because the rest o…

  4. Convert 8-bit representation to 16-bit representation of: two’s–complement binary 0110 0100 using sign extension.

    0000 0000 0110 0100

  5. Express -3 in 4-bit excess-8 notation.

    -3 + 8 = 5 (find -3 + bias) convert 5 to binary = 0101.

  6. Calculate -1 + 5 in two's complement.

    Carry-bit would set a carry-out ALU flag, and can be safely ignored since we're doing signed number oprations (and we're still getting the right result). 111 + 101 ____ 1100 => 100

  7. Which of the 4 is most commonly used for storing negative numbers, and why? signed magnitude one's complement two's complement excess-n

    Two's complement. Signed magnitude has 2 problems: it has negative and positive 0s, and extra circuitry is needed to be checking for their equality in order to calculate something in ALU, CPU needs to convert it to one's complement first (or gibberish will be returned) and then back, which, again, requires more circuitry One's complement has 1 problem: shared negative 0 with signed magnitude system Two's complement doesn't have any of these problems. Both ARM and x86 use two's complement.

  8. What is sign extension used for?

    For increasing amount of bits without affecting stored number's value. Method of sign extension (fill in with sign bit, or maybe fill in with zeroes) depends on how our number is stored (two's complement, or maybe just unsigned number). Two's complement sign extension is the process of converting a N–bit representation to a larger format; e.g., a 16–bit number to a 32–bit number, by extending the sign bit to fill the new “high order” bits.

  9. This is number 3 in binary: 0011. Find how -3 would be represented in: signed magnitude one's complement two's complement

    signed magnitude - 1011 one's complement - 1100 two's complement - 1101

  10. Express 7 in 5 bits two's complement. Express -7 in 5 bits two's complement.

    7: 001112 -7: 110012

  11. 10011 is expressed in 5 bits 2's complement. What is it in ordinary notation?

    That's how we'd convert number to two's complement notation: turn sign bit into a sign invert all numbers (except for the sign bit) plus one Doing this in reverse, we're getting: -11012

  12. These 2 numbers are represented in 2's complement: 0110 + 10 Add them in 2's complement.

    We need to sign extend a second number to 4 bits. 0110 + 1110 = 10100 (MSB is a carry-out, and we can safely ignore it because we're doing a signed integer calculation) = 0100 in 2's complement. CHECKING 0110 in 2's complement = 6 10 in 2's complement = -2 0100 in 2's complement = 4.

  13. What is the difference between: the twos complement representation of a number and the twos complement of a number? Give an example.

    twos complement representation of a number: bit pattern used to represent an integer twos complement of a number: operation E.g.: 7 in two's complement is 0111. two's complement of 7 in a 4-bit register is actually the "1001", which is -7 in two's complement representation.

  14. Starting with any number in two's-complement representation, if all the bits are flipped and 1 added, negative of that number is obtained. What's the exception?

    Most negative number is an exception! E.g. 1000 in two's complement is -8. Although the number is an exception, it is a valid number in regular two's complement systems. All arithmetic operations work with it both as an operand and (unless there was an overflow) a result.

  15. We have 3 bits to store numbers, and we decide to store them in two's complement. What will be the largest and the smallest numbers stored?

    Largest: 011 (which is logical - 0 for positive, and two 1s) Smallest: 100 (which is an exception) So we will have 23 = 8 numbers : -4, -3, -2, -1, 0, 1, 2, 3

  16. Usually two's complement in n-bit representation of a number is found by: flipping all bits + 1 What's the other way to get two's complement?

    two's complement of a = 2n − a ________________________ Example of a 10's complement: 4 - 3 = 4 + (10 - 3)[this is two's complement of a number] - 10[this is carry out]

  17. There are two ways to find n-bit two's complement of a: represent in n-bit binary, flip all bits, and + 1 2n - a, and represent it in binary Name 3 facts that explain why these ways are identical.

    28 − a = [(28 − 1) − a] + 1. The binary representation of 28 − 1 is 111111112. Subtracting an 8-bit binary number a from 111111112 just switches all the 0’s in a to 1’s and all the 1’s to 0’s.

  18. Show why 2's complement of the 2’s complement of a number is the number itself. (Suppose we're working in 8 bits)

    8-bit 2's complement of a is defined as 2n - a. 28 − (28 − a) = a