Adobe Interview Question
If we assume that the maximum word length is 8 bits,
The binary representation of -5 is 1000 0101
Then, 1's complement is 0111 1010
2's complement is 0111 1011
beginning with the signed 8-bit binary representation of the decimal value 5, using subscripts to indicate the base of a representation needed to interpret its value:
000001012 = 510
The most significant bit is 0, so the pattern represents a non-negative (positive) value. To convert to −5 in two's-complement notation, the bits are inverted; 0 becomes 1, and 1 becomes 0:
11111010
At this point, the numeral is the ones' complement of the decimal value 5. To obtain the two's complement, 1 is added to the result, giving:
111110112 = − 510
The result is a signed binary number representing the decimal value −5 in two's-complement form. The most significant bit is 1, so the value represented is negative.
beginning with the signed 8-bit binary representation of the decimal value 5, using subscripts to indicate the base of a representation needed to interpret its value:
00000101 = 5
The most significant bit is 0, so the pattern represents a non-negative (positive) value. To convert to −5 in two's-complement notation, the bits are inverted; 0 becomes 1, and 1 becomes 0:
11111010
At this point, the numeral is the ones' complement of the decimal value 5. To obtain the two's complement, 1 is added to the result, giving:
11111011 = − 5
The result is a signed binary number representing the decimal value −5 in two's-complement form. The most significant bit is 1, so the value represented is negative.
binary: 0000 0101
- Anonymous March 11, 20101s complement: 1111 1010
add 1 to get 2s complement: 1111 1011