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

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
主站蜘蛛池模板: 西畴县| 乐业县| 博乐市| 于田县| 奇台县| 郸城县| 新昌县| 崇信县| 东阿县| 科技| 双流县| 富锦市| 新平| 顺昌县| 横山县| 四平市| 阳春市| 广平县| 天水市| 突泉县| 金山区| 高密市| 麻栗坡县| 德惠市| 徐州市| 呼和浩特市| 渭源县| 凤庆县| 城口县| 丹巴县| 四川省| 余江县| 台州市| 朝阳县| 城口县| 阳东县| 牡丹江市| 白城市| 乃东县| 定安县| 萍乡市|