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

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
主站蜘蛛池模板: 西安市| 建平县| 尉氏县| 长武县| 迁西县| 龙游县| 河曲县| 上饶县| 桂阳县| 五莲县| 禄丰县| 稷山县| 深泽县| 辽阳县| 柘荣县| 卓资县| 南昌县| 阳山县| 平定县| 温宿县| 遂溪县| 清涧县| 特克斯县| 静安区| 永和县| 兴国县| 宁河县| 额尔古纳市| 舞钢市| 武山县| 罗山县| 河北区| 如皋市| 五台县| 怀宁县| 吴桥县| 资溪县| 乌兰浩特市| 微博| 玉林市| 平阳县|