User Tools

Site Tools


tanszek:oktatas:techcomm:encoding_integers

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tanszek:oktatas:techcomm:encoding_integers [2026/10/12 18:29] – kneheztanszek: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<sup>8</sup> = 256 possible bit patterns. 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<sup>8</sup> = 256 possible bit patterns.
Line 11: Line 11:
 === Unsigned integers === === Unsigned integers ===
  
-In ordinary decimal notation, the positions of the digits have weights of 1, 10, 100, and so on, starting from the right.+In ordinary decimal notation, digit positions have weights of 1, 10, 100, and so on, starting from the right.
  
 In binary notation, the weights are powers of two: In binary notation, the weights are powers of two:
Line 148: Line 148:
 </code> </code>
  
-The expected result is +2. To obtain it, an arithmetic procedure for sign-magnitude numbers must take the signs into account and subtract the magnitudes.+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's complement representation**. A widely used alternative for signed integers is **two's complement representation**.
  
-Its main advantage is that positive and negative integers can be added using the same binary addition procedure as unsigned 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 differs from the unsigned case.
  
 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 discards the carry-out. **A carry-out does not, by itself, indicate signed overflow.**
  
 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, so their rules must also be checked when writing a program.+These examples describe fixed-width binary arithmetic. Programming languages may handle out-of-range calculations differently, so you must also check their rules when writing a program.
  
 === Check your understanding === === Check your understanding ===
tanszek/oktatas/techcomm/encoding_integers.1791829799.txt.gz · Last modified: by knehez