Positive and negative numbers can be represented in many ways in a computer. List some of the ways of representing signed numbers. Can you think of any other ways of representing signed values?
What will be an ideal response?
There are four common ways of representing signed numbers in computing:
a. One’s complement; the number begins with 0 for positive values and 1 for negative values. If the number has n bits, n?1 bits are used for the number and one for its polarity (i.e., sign). A negative number is obtained from a positive number by inverting bits; for example, if 12 in six bits is 001100 then ?12 is 110011. One’s complement is little used today. It has the disadvantage that there are two values for zero: 000…0 is +0 and 111…1 is ?0.
b. Two’s complement: like 1’s complement, the most?significant bit is a sign bit. A two’s complement number is formed by inverting the bits and then adding 1 (i.e., one’s and two’s complement negative values differ by 1). If 12 is 001100, ?12 is 110011 + 1 = 110100. A two’s complement number has a single value for zero, 000...0, and is a true complement because × + ?x = 0 (e.g., 12 + ?12 = 001100 + 110100 = 1 000000). The addition of two numbers generates a carry bit that is not part of the result. Two’s complement representation is the standard form of representing signed integers. It is used because addition and subtraction are the same operation; that is x ? y is evaluated by x + (?y).
c. Sign and magnitude representation is the simplest way of representing signed values. You take the mostsignificant bit and use it as a sign (0 = + and 1 = ?); for example, +12 = 001100 and ?12 = 101100. Sign and magnitude representation has two values for 0 and you can’t use the same hardware for addition and subtraction. It is used largely to represent floating?point values.
d. Excess notation. One way of dealing with negative values is to get rid of negative numbers. Six bits can represent the unsigned integer range 0 to 63. Suppose we call these numbers ?32 to 31 so that 000000 is ? 32, 000001 is 31, … , 100000 is 0, 100001 is 1, …, and 111111 is 31. Now we have a continuous sequence of positive numbers that represent ?32 to 31 This representation is called ‘excess’, because we add a bias or constant to each number to convert it to its excess representation form. For example, in 6 bits ?5 becomes ? 5 + 32 = 27 = 011011. The advantage of this representation is that numbers are monotonic from the most negative to most positive (monotonic means that if two numbers differ by 1, their representation differs by 1 in two’s complement form, 0 is 0000..0 and ?1 is 1111..11). This form of representing negative values is used to represent exponents in floating?point.
e. You can represent negative numbers in many ways; for example, negabinary numbers use positional weighting with the nth digit being weighted by (?2)n. The position values would be +64 ?32 +16 ?8 +4 ?2 +1; for example 0011011 would represent 0 + 0 + 16 ?8 + 0 ? 2 + 1 = +7.
You might also like to view...
The top-level domain indicates when the Web site was created.
Answer the following statement true (T) or false (F)
The ________ tab type is when the text is centered around the tab stop
A) center B) left C) decimal D) right
Construct a hash tree for the above candidate 3-itemsets. Assume the tree uses a hash function where all odd-numbered items are hashed to the left child of a node, while the even-numbered items are hashed to the right child. A candidate k-itemset is inserted into the tree by hashing on each successive item in the candidate and then following the appropriate branch of the tree according to the hash value. Once a leaf node is reached, the candidate is inserted based on one of the following conditions: Condition 1: If the depth of the leaf node is equal to k (the root is assumed to be at depth 0), then the candidate is inserted regardless of the number of itemsets already stored at the node. Condition 2: If the depth of the leaf node is less than k, then the candidate can be inserted as long
Consider the following set of candidate 3-itemsets: {1, 2, 3}, {1, 2, 6}, {1, 3, 4}, {2, 3, 4}, {2, 4, 5}, {3, 4, 6}, {4, 5, 6}
Which of the following is not true of static local variables?
a) They’re accessible outside of the function in which they are de-fined. b) They retain their values when the function is exited. c) They’re initialized to zero if not explicitly initialized by the pro-grammer. (d) They can be pointers.