tanszek:oktatas:techcomm:encoding_integers
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
tanszek:oktatas:techcomm:encoding_integers [2024/09/30 18:50] – knehez | tanszek:oktatas:techcomm:encoding_integers [2024/09/30 18:54] (current) – [How to convert decimal integers to binary form] knehez | ||
---|---|---|---|
Line 53: | Line 53: | ||
==== How to convert decimal integers to binary form ==== | ==== 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, | ||
+ | |||
+ | **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.1727722230.txt.gz · Last modified: 2024/09/30 18:50 by knehez