tanszek:oktatas:techcomm:encoding_integers
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| tanszek:oktatas:techcomm:encoding_integers [2026/10/12 18:29] – knehez | tanszek:oktatas:techcomm:encoding_integers [2026/10/12 18:32] (current) – knehez | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ==== Integer representations ==== | + | ===== Integer representations |
| Computers store data as bits. Each bit can have one of two values: 0 or 1. A byte consists of 8 bits, so it has 2< | Computers store data as bits. Each bit can have one of two values: 0 or 1. A byte consists of 8 bits, so it has 2< | ||
| Line 11: | Line 11: | ||
| === Unsigned integers === | === Unsigned integers === | ||
| - | In ordinary decimal notation, | + | In ordinary decimal notation, |
| In binary notation, the weights are powers of two: | In binary notation, the weights are powers of two: | ||
| Line 148: | Line 148: | ||
| </ | </ | ||
| - | The expected result is +2. To obtain | + | The expected result is +2. To get it, an arithmetic procedure for sign-magnitude numbers must account for the signs and subtract the magnitudes. |
| === Two's complement representation === | === Two's complement representation === | ||
| Line 154: | Line 154: | ||
| A widely used alternative for signed integers is **two' | A widely used alternative for signed integers is **two' | ||
| - | Its main advantage is that positive and negative integers | + | Its main advantage is that you can add positive and negative integers using the same binary addition procedure as with unsigned integers. |
| Let us first see what bit pattern would make this possible. | Let us first see what bit pattern would make this possible. | ||
| Line 216: | Line 216: | ||
| | Weight | **−128** | 64 | 32 | 16 | 8 | 4 | 2 | 1 | | | Weight | **−128** | 64 | 32 | 16 | 8 | 4 | 2 | 1 | | ||
| - | Only the weight of the leftmost bit differs from the unsigned case. | + | Only the leftmost bit's weight |
| Consequently: | Consequently: | ||
| Line 278: | Line 278: | ||
| The result is correct. | The result is correct. | ||
| - | The carry-out is discarded in this fixed-width calculation. **A carry-out does not, by itself, indicate signed overflow.** | + | This fixed-width calculation |
| Two's complement makes addition convenient, but the result must still fit in the available signed range. | Two's complement makes addition convenient, but the result must still fit in the available signed range. | ||
| Line 308: | Line 308: | ||
| **Carry-out and signed overflow describe different conditions.** | **Carry-out and signed overflow describe different conditions.** | ||
| - | These examples describe fixed-width binary arithmetic. Programming languages may handle out-of-range calculations differently, | + | These examples describe fixed-width binary arithmetic. Programming languages may handle out-of-range calculations differently, |
| === Check your understanding === | === Check your understanding === | ||
tanszek/oktatas/techcomm/encoding_integers.1791829799.txt.gz · Last modified: by knehez
