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

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
主站蜘蛛池模板: 峨山| 施甸县| 柯坪县| 临朐县| 建阳市| 大余县| 灯塔市| 内乡县| 尚志市| 鄂尔多斯市| 濉溪县| 孝义市| 祁东县| 新乐市| 钦州市| 房产| 石台县| 天峻县| 江油市| 南宫市| 三门峡市| 松原市| 来凤县| 甘谷县| 常宁市| 东至县| 太康县| 桑日县| 南昌县| 高要市| 九龙城区| 南阳市| 策勒县| 晋宁县| 延川县| 锦州市| 固镇县| 桦川县| 静海县| 贵港市| 新泰市|