C语言英文课件11:位运算
合集下载
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
5. Number Expressed in Computer──Complement Code
In compute system , digits are all express in complement code, the reason is that: we can do with sign bit and other bits together; Also minus can be done as plus done. Besides, when two numbers which are expressed in complement code do plus operation, if there is a enter to the highest bit, the enter bit is abandoned.
Hale Waihona Puke 6.Move right each bit──>> (1)formate:x>>a number (2)rule: make each bit move right, the lowest bit which is moved out will be abandoned ; the highest bit:
76543210
Fig 11-1 The number of each bit in one byte
2.Digit Expressed by Initial Code Digit expressed by initial code is that using the highest bit as a sign bit( 0 refers to positive number, 1 refers to negative number), the other bits represent to themselves’ absolute value ( expressed in binary). In order to simple description , we use one byte to express one integral in this class.
Bit operation is that we do it in binary.
11.1 number expressed in computer 11.2 bit operation 11.3 bit segment
11.1 Number Expressed in Computer
1.Bit and Byte Memory in computer system is constituted of many named byte units. One byte is made up of eight bits ,and the value is 0 or 1 of every bit. The bit in the right side is called “the lowest bit”, and its number is 0. The bit in the left side is called “the highest bit”, and set the number to each bit from the lowest to highest in order. Diagram 11-1 is the number of each bit in one byte .
0011 | 1001 ────
1011=11 (3)main usage: set some bit to 1 of a number, other bits is not changed.
3.XOR each bit──^ (1)formate:x^y (2)rule:when correspond bit is the same, it is 0. when it is different , it is 1:3^9=10。 (3)Main usage:make some bit to convert (if it is 1,it will be turned to 0. if it is 0,it will be turned to 1),other bits are all not changed. 4.Convert each bit──~ (1)formate:~x (2)rule:convert each bit is that if it is 1 ,it will be turned to 0, else it will be turned to 1:in IBM-PC compute,~0=0xffff,~9=0xfff6。 (3)Main usage:make a number indirectly , so it strengths transplant of programs. 5.Move left each bit──<< (1)formate:x<<a number (2)rule:make each bit move left, the lowest bit set to 0, the highest bit is overflow :5<<2=20。
(2)if the complement code’s sign bit is “1”, it is a negative number, so the operation of observing an initial code can be : sign bit is not changed, other bits is opposite to their absolute value’s initial code. Then it adds 1.
1)To unsigned numbers and signed positive numbers, it will be set 0 ;
If we know the complement code of a number, there are two circumstances about the initial code:
(1)if the complement code’s sign bit is “0”, it is a positive number, so complement code is just its initial code.
0011 & 1001 ────
0001=1 (3)main usage: take( or save ) some bit of a number, other bits are 0.
2.Or each bit in order──| (1)formate:x|y (2)rule:only when correspond bit is 0, it is 0. Otherwise it is 1. For example,3|9=11:
For example, the opposite code of +9 is 00001001。 (2) opposite code of negative number: sign bit is 1, other bits is opposite to their absolute value (1 turns to 0, 0 turns to 1). For example, the opposite code of -9 is: because it is a negative number , sign bit is 1; other seven bits is the opposite of its absolute value that the initial of +9 , so the opposite of -9 is 11110110.
11.2 Bit Operation
11.2.1 Bit Operation and Its Operation Signs
1.And each bit in order──& (1)formate:x&y (2)rule:only when correspond bit is 1, it is a. Otherwise it is 0: For example,3&9=1:
3.Digit Expressed by Opposite Code digit expressed by opposite code includes two circumstances: (1)opposite code of positive number: the same as the initial code.
For example, the complement code of -9 is: because it is a negative number, sign bit is 1, other seven bits is the opposite of its absolute value that the initial of +9 , so the opposite code of -9 is 11110110. Then it adds 1. So the complement of -9 is 11110111.
For example, it is given a complement code that is 11111001, so its initial code is 10000111(-7):because its sign bit is “1”, it is a negative number, the sign bit needn’t changed, it is still “1”; other seven bits is the opposite of 1111001, so it is 0000110 now;then it adds 1. It is 10000111。
For example, the complement code of +9 is 0001001. (2)the complement of negative number: sign bit is 1, other bits is opposite to their absolute value’s initial code, then add 1.
For example, the initial code of +9 is 00001001
└→sign bit 0 refers to positive number the initial code of -9 is 10001001。
└→ sign bit 0 refers to negative number
4. Digit Expressed by Complement Code
Digit expressed by complement code also includes two circumstances :
(1)the complement code of positive number: the same as the initial code.
Chapter 11 Bit Operation
In order to save memory space, several status signs are usually put together into one byte ( or bit ).C language is designed for studying system software, so it offers bit operation which separate status sign from sign byte memory.
In compute system , digits are all express in complement code, the reason is that: we can do with sign bit and other bits together; Also minus can be done as plus done. Besides, when two numbers which are expressed in complement code do plus operation, if there is a enter to the highest bit, the enter bit is abandoned.
Hale Waihona Puke 6.Move right each bit──>> (1)formate:x>>a number (2)rule: make each bit move right, the lowest bit which is moved out will be abandoned ; the highest bit:
76543210
Fig 11-1 The number of each bit in one byte
2.Digit Expressed by Initial Code Digit expressed by initial code is that using the highest bit as a sign bit( 0 refers to positive number, 1 refers to negative number), the other bits represent to themselves’ absolute value ( expressed in binary). In order to simple description , we use one byte to express one integral in this class.
Bit operation is that we do it in binary.
11.1 number expressed in computer 11.2 bit operation 11.3 bit segment
11.1 Number Expressed in Computer
1.Bit and Byte Memory in computer system is constituted of many named byte units. One byte is made up of eight bits ,and the value is 0 or 1 of every bit. The bit in the right side is called “the lowest bit”, and its number is 0. The bit in the left side is called “the highest bit”, and set the number to each bit from the lowest to highest in order. Diagram 11-1 is the number of each bit in one byte .
0011 | 1001 ────
1011=11 (3)main usage: set some bit to 1 of a number, other bits is not changed.
3.XOR each bit──^ (1)formate:x^y (2)rule:when correspond bit is the same, it is 0. when it is different , it is 1:3^9=10。 (3)Main usage:make some bit to convert (if it is 1,it will be turned to 0. if it is 0,it will be turned to 1),other bits are all not changed. 4.Convert each bit──~ (1)formate:~x (2)rule:convert each bit is that if it is 1 ,it will be turned to 0, else it will be turned to 1:in IBM-PC compute,~0=0xffff,~9=0xfff6。 (3)Main usage:make a number indirectly , so it strengths transplant of programs. 5.Move left each bit──<< (1)formate:x<<a number (2)rule:make each bit move left, the lowest bit set to 0, the highest bit is overflow :5<<2=20。
(2)if the complement code’s sign bit is “1”, it is a negative number, so the operation of observing an initial code can be : sign bit is not changed, other bits is opposite to their absolute value’s initial code. Then it adds 1.
1)To unsigned numbers and signed positive numbers, it will be set 0 ;
If we know the complement code of a number, there are two circumstances about the initial code:
(1)if the complement code’s sign bit is “0”, it is a positive number, so complement code is just its initial code.
0011 & 1001 ────
0001=1 (3)main usage: take( or save ) some bit of a number, other bits are 0.
2.Or each bit in order──| (1)formate:x|y (2)rule:only when correspond bit is 0, it is 0. Otherwise it is 1. For example,3|9=11:
For example, the opposite code of +9 is 00001001。 (2) opposite code of negative number: sign bit is 1, other bits is opposite to their absolute value (1 turns to 0, 0 turns to 1). For example, the opposite code of -9 is: because it is a negative number , sign bit is 1; other seven bits is the opposite of its absolute value that the initial of +9 , so the opposite of -9 is 11110110.
11.2 Bit Operation
11.2.1 Bit Operation and Its Operation Signs
1.And each bit in order──& (1)formate:x&y (2)rule:only when correspond bit is 1, it is a. Otherwise it is 0: For example,3&9=1:
3.Digit Expressed by Opposite Code digit expressed by opposite code includes two circumstances: (1)opposite code of positive number: the same as the initial code.
For example, the complement code of -9 is: because it is a negative number, sign bit is 1, other seven bits is the opposite of its absolute value that the initial of +9 , so the opposite code of -9 is 11110110. Then it adds 1. So the complement of -9 is 11110111.
For example, it is given a complement code that is 11111001, so its initial code is 10000111(-7):because its sign bit is “1”, it is a negative number, the sign bit needn’t changed, it is still “1”; other seven bits is the opposite of 1111001, so it is 0000110 now;then it adds 1. It is 10000111。
For example, the complement code of +9 is 0001001. (2)the complement of negative number: sign bit is 1, other bits is opposite to their absolute value’s initial code, then add 1.
For example, the initial code of +9 is 00001001
└→sign bit 0 refers to positive number the initial code of -9 is 10001001。
└→ sign bit 0 refers to negative number
4. Digit Expressed by Complement Code
Digit expressed by complement code also includes two circumstances :
(1)the complement code of positive number: the same as the initial code.
Chapter 11 Bit Operation
In order to save memory space, several status signs are usually put together into one byte ( or bit ).C language is designed for studying system software, so it offers bit operation which separate status sign from sign byte memory.