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 [2024/09/30 18:21] kneheztanszek:oktatas:techcomm:encoding_integers [2024/09/30 18:54] (current) – [How to convert decimal integers to binary form] knehez
Line 51: Line 51:
  
 This is the reason why we are using the special two's complement form. Without using this encoding, we cannot add negative and positive numbers. This is the reason why we are using the special two's complement form. Without using this encoding, we cannot add negative and positive numbers.
 +
 +==== How to convert decimal integers to binary form ====
 +
 +Let’s convert the decimal number **156** into binary.
 +
 +==== Step 1: Divide the decimal number by 2 ====
 +Start by dividing the decimal number (156) by 2 and keep track of the quotient and remainder. The remainder will be either 0 or 1, which forms the binary digits from bottom to top.
 +
 +| **Division** | **Quotient** | **Remainder** |
 +| 156 ÷ 2          | 78       | 0         |
 +| 78 ÷ 2           | 39       | 0         |
 +| 39 ÷ 2           | 19       | 1         |
 +| 19 ÷ 2           | 9        | 1         |
 +| 9 ÷ 2            | 4        | 1         |
 +| 4 ÷ 2            | 2        | 0         |
 +| 2 ÷ 2            | 1        | 0         |
 +| 1 ÷ 2            | 0        | 1         |
 +
 +==== Step 2: Write the binary digits ====
 +To get the binary representation, take the remainders from bottom to top. The binary equivalent of **156** is:
 +
 +**10011100₂**
 +
 +==== Verification ====
 +To verify, we can convert the binary number back to decimal:
 +
 +  (1 × 2⁷) + (0 × 2⁶) + (0 × 2⁵) + (1 × 2⁴) + (1 × 2³) + (1 × 2²) + (0 × 2¹) + (0 × 2⁰)
 +  = 128 + 0 + 0 + 16 + 8 + 4 + 0 + 0
 +  = 156
 +
 +Hence, the binary representation of 156 is correct.
 +
 +
tanszek/oktatas/techcomm/encoding_integers.1727720494.txt.gz · Last modified: 2024/09/30 18:21 by knehez