官术网_书友最值得收藏!

Binary arithmetic

Since a byte is the common unit used in computers, let's play with it. We can start with basic arithmetical functions: addition, subtraction, multiplication, and division. The pencil-and-paper method is still a strong method for doing binary math. Binary arithmetic is similar to doing arithmetic in decimal numbers. The difference is that there are only two numbers used, 1 and 0.

Addition is carried out as follows:

  1b               10101b
+ 1b + 1111b
10b 100100b

An example of subtraction is as follows:

 10b               1101b
- 1b - 111b
1b 110b

Multiplication is carried out as follows:

   101b             1b x 1b = 1b
x 10b 1b x 0b = 0b
000
101
1010b

Division in binary works as follows:

       1010b                         1000b 
10b | 10100b 11b | 11010b
-10 -11
010 0010
-10 -000
00 10b (remainder)
-0
0
主站蜘蛛池模板: 太保市| 太原市| 通辽市| 西和县| 西藏| 邯郸县| 新疆| 本溪| 阿尔山市| 邵东县| 游戏| 鸡西市| 宝坻区| 诸暨市| 瑞丽市| 乐山市| 侯马市| 平遥县| 仁怀市| 什邡市| 永福县| 乐平市| 大丰市| 鄯善县| 故城县| 五河县| 平阳县| 探索| 五寨县| 普洱| 化州市| 什邡市| 姜堰市| 凯里市| 汉阴县| 龙岩市| 阿瓦提县| 从化市| 鹿泉市| 百色市| 鄂伦春自治旗|