Lesson 54: Negative numbers
이 페이지는 최신 브라우저(SharedArrayBuffer 지원)가 필요합니다. Chrome, Edge, Firefox 또는 Safari를 최신 버전으로 업데이트해 주세요.
English
Below zero
- 8 bits can store 0 to 255. To store negative numbers too, computers use two's complement.
- The leftmost bit is worth −128. All the other bits keep their normal values.
- So 8-bit two's complement stores −128 to +127.
Words for this lesson
| Word | Meaning |
|---|---|
| two's complement | binary for positive and negative whole numbers |
| most significant bit | the leftmost bit; 1 means negative |
| flip | change every 0 to 1 and every 1 to 0 |
English
Place values
| −128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|---|---|---|---|---|---|---|
| 1 | 0 | 1 | 0 | 0 | 0 | 1 | 1 |
- −128 + 32 + 2 + 1 = −93.
English
Make −32 (flip and add 1)
| Step | Bits |
|---|---|
| +32 | 0010 0000 |
| flip | 1101 1111 |
| add 1 | 1110 0000 |
English
In the exam
- 0478/11/M/J/24 Q3(c): convert 10100011 to denary. Mark scheme: −93, with working such as flip and add.
- 0478/12/M/J/24 Q3(d): −32 as a two's complement integer. Mark scheme: 11100000.
- 0478/13/O/N/24 Q1(e): 10001110 in denary. Mark scheme: −114.
- 0478/13/M/J/25 Q1(d): 11001001 in denary. Mark scheme: −55, method flip and add 1.
- 0478/13/O/N/23 Q2(d): the positive number 123 in 8-bit two's complement: 01111011, the same as normal binary.
난이도 4/5 · 280코인 + 오늘 첫 완료 시 작은 보너스 추가
Type an 8-bit two's complement number, for example 10100011. The program already reads it as a normal binary number (163). In two's complement the leftmost bit is worth −128, not +128. So if the first bit is 1, take 256 away. Print Denary: and the value.
출력을 보려면 '실행'을 클릭하세요.
난이도 4/5 · 280코인 + 오늘 첫 완료 시 작은 보너스 추가
Now make a negative number with the exam method. Type a positive number from 0 to 127, for example 32. The program prints it in 8 bits. Then flip every bit (0 becomes 1, 1 becomes 0) and print Flip: and the bits; then 1 추가 and print Add 1: and the bits. The result is −32 in two's complement.
출력을 보려면 '실행'을 클릭하세요.