Status: Tags: #archivedCards/macm101/numbertheory #aCards/cmpt295/binary Links: Nand2Tetris MOC
Binary
Principles
Using 0’s and 1’s to represent digits
General Form
- Keep dividing quotient by 2, get remainder, and keep doing
Find binary expansion of 165
?
Examples
Int in C
- Last one determines sign
Decimal | Binary | |
---|---|---|
-2147483648 | 10000000 00000000 00000000 00000000 | |
-2147483647 | 10000000 00000000 00000000 00000001 | ___ |
Converting
Steps to convert negative number to binary ?
- Take positive form
- Negate it (0’s become 1’s, 1’s become 0’s)
- Add 1
Steps to convert signed to unsigned ?
- Add value of last binary digit
Steps to convert unsigned to signed ?
- Subtract value of last binary digit
Exercises
- Convert 10011011 from binary to decimal.
- Convert 29 from decimal to binary.
- Write a program that get an integer in decimal and print its binary form.
Backlinks
References: