Книга: Advanced PIC Microcontroller Projects in C
1.7 Converting Decimal Numbers into Binary
Разделы на этой странице:
1.7 Converting Decimal Numbers into Binary
To convert a decimal number into binary, divide the number repeatedly by 2 and take the remainders. The first remainder is the least significant digit (LSD), and the last remainder is the most significant digit (MSD).
Example 1.3
Convert decimal number 2810 into binary.
Solution 1.3
Divide the number into 2 repeatedly and take the remainders:
28/2 ? 14 Remainder 0 (LSD)
14/2 ? 7 Remainder 0
7/2 ? 3 Remainder 1
3/2 ? 1 Remainder 1
1/2 ? 0 Remainder 1 (MSD)
The binary number is 111002.
Example 1.4
Convert decimal number 6510 into binary.
Solution 1.4
Divide the number into 2 repeatedly and take the remainders:
65/2 ? 32 Remainder 1 (LSD)
32/2 ? 16 Remainder 0
16/2 ? 8 Remainder 0
8/2 ? 4 Remainder 0
4/2 ? 2 Remainder 0
2/2 ? 1 Remainder 0
1/2 ? 0 Remainder 1 (MSD)
The binary number is 10000012.
Example 1.5
Convert decimal number 12210 into binary.
Solution 1.5
Divide the number into 2 repeatedly and take the remainders:
122/2 ? 61 Remainder 0 (LSD)
61/2 ? 30 Remainder 1
30/2 ? 15 Remainder 0
15/2 ? 7 Remainder 1
7/2 ? 3 Remainder 1
3/2 ? 1 Remainder 1
1/2 ? 0 Remainder 1 (MSD)
The binary number is 11110102.
- 1.1 Introduction
- 1.2 Microcontroller Systems
- 1.3 Microcontroller Features
- 1.4 Microcontroller Architectures
- 1.5 Number Systems
- 1.6 Converting Binary Numbers into Decimal
- 1.7 Converting Decimal Numbers into Binary
- 1.8 Converting Binary Numbers into Hexadecimal
- 1.9 Converting Hexadecimal Numbers into Binary
- 1.10 Converting Hexadecimal Numbers into Decimal
- 1.11 Converting Decimal Numbers into Hexadecimal
- 1.12 Converting Octal Numbers into Decimal
- 1.13 Converting Decimal Numbers into Octal
- 1.14 Converting Octal Numbers into Binary
- 1.15 Converting Binary Numbers into Octal
- 1.16 Negative Numbers
- 1.17 Adding Binary Numbers
- 1.18 Subtracting Binary Numbers
- 1.19 Multiplication of Binary Numbers
- 1.20 Division of Binary Numbers
- 1.21 Floating Point Numbers
- 1.22 Converting a Floating Point Number into Decimal
- 1.23 BCD Numbers
- 1.24 Summary
- 1.25 Exercises
- Hexadecimal, or ‘hex’ to its friends
- Maintaining Accurate Serial Numbers
- Numbers
- 13.5. Binary Utilities
- 13.6. Miscellaneous Binary Utilities
- 1.6 Converting Binary Numbers into Decimal
- 1.8 Converting Binary Numbers into Hexadecimal
- 1.9 Converting Hexadecimal Numbers into Binary
- 1.10 Converting Hexadecimal Numbers into Decimal
- 1.11 Converting Decimal Numbers into Hexadecimal
- 1.12 Converting Octal Numbers into Decimal
- 1.13 Converting Decimal Numbers into Octal