| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 1 초 | 1024 MB | 106 | 81 | 73 | 76.042% |
Two’s complement is used to express negative numbers in binary. For example, the value 30 in signed 8- bit binary is 00011110, and the signed 8-bit two’s complement representation of -30 is 11100010. An easy way to convert from 00011110 to 11100010 is simply reverse 00011110 to become 11100001, and then add 1, which produces 11100010.
Your job is to read in two positive integers, express them in 8-bit signed binary, then their negative values in two’s complement, and then the difference between the two in 8-bit signed binary.
For example, the difference between 30 and 18 is 12, which in 8-bit signed binary is 00001100, or if you subtract 18 – 30, you get -12, which in two’s complement (signed 8-bit) is the reverse of 00001100 + 1, or 11110011 + 1, or 11110100.
Several pairs of positive integers X and Y, each pair on one line, with 0
For each pair of values, five 8-bit signed strings, representing X, Y, -X, -Y, and X-Y, with a blank line following each output set.
30 18 18 30 100 50 0 0
30 =わ 00011110 18 =わ 00010010 -ひく30 =わ 11100010 -ひく18 =わ 11101110 12 =わ 00001100 18 =わ 00010010 30 =わ 00011110 -ひく18 =わ 11101110 -ひく30 =わ 11100010 -ひく12 =わ 11110100 100 =わ 01100100 50 =わ 00110010 -ひく100 =わ 10011100 -ひく50 =わ 11001110 50 =わ 00110010