Bit Operators:
can directly manipulate the content of the binary digits; ~ is a unary bit operator, it can be based on a number to calculate another number, these two numbers all binary digits of the content of the number are different (inverse by bit), the use of this symbol should be written in front of the number
Binary Operators: These include bitwise and (&), bitwise or (|), and bitwise iso (^), all of which can compute the contents of two digits corresponding to a binary digit.
Push-to-talk with (&)
You can calculate the content of the corresponding digits of two numbers; as long as the content of one digit is 0, the result of the calculation is 0.
3 0000 0011
& 5 0000 0101
0000 0001
Any number of digits and 0 to do the press with the result must be 0, any number of digits and 1 to do the press with the result remains unchanged, press with can be used to obtain the content of certain digits, press with can also be used to set the content of some digits to 0.
Bitwise or (|)
You can orchestrate the content of the corresponding digits of two numbers; as long as the content of one digit is 1, the result of orchestration will be 1.
3 0000 0011
| 5 0000 0101
0000 0111
Any number of digits and 0 do press or the result remains unchanged; any number of digits and 1 do press or the result is 1, press or can set the content of some digits to 1
Bitwise heterodyne (^)
Can be the corresponding digit content of the two numbers to do the calculation of dissimilarity, if the content of the two digits is the same, the result of the dissimilarity is 0, otherwise the result is 1
3 0000 0011
^ 5 0000 0101
0000 0110
The content of any digit and 0 do perpositional dissimilarity remain unchanged; the content of any digit and 1 do perpositional dissimilarity must be changed, perpositional dissimilarity can be some of the digits of the content of the opposite content
'a' 97 0110 0001
'A' 65 0100 0001
ch &=32;
ch |=32;
ch ^=32;
shift operator (computing)
The contents of all binary digits in a number can be shifted uniformly to the left or right by n positions.
'>>' indicates a shift to the right
'<<' indicates a shift to the left;
They are dual purpose bit operator, the operator is the left side of the number to be shifted, the right side of the operator is the number of digits to be moved, the shift operation is essentially the contents of each digit into another digit, shifted to the left when the right side of the empty digit must be filled with zeros, the right side of the unsigned type of digit shifted to the right when the left side of the empty digit is filled with zeros; signed type of digit shifted to the right when the left side is filled with symbols (1 or 0). When a signed number is shifted right, the empty digit on the left is filled with the content of the sign bit (1 or 0). In general, moving n places to the left is equivalent to multiplying by 2 to the nth power, and moving n places to the right is equivalent to dividing by 2 to the nth power. All bitwise operators do not modify the contents of the memory area.
& can also be used as a unary operator, this time it can be used to calculate the address of a memory area; when using this operator should be written in front of a memory area, you can use the %p placeholder to display the address data in the terminal window. All address data in our computers consists of 32 binary digits.
* can also be used as a unary operator, this time it can find the corresponding storage area based on an address, this operator should be written in front of an address data.
trinomial operator (math.)
One of the two sets of calculation rules can be selected for the calculation, and the trinomial operator is formatted as follows:
Boolean value ? Formula 1: Formula 2; Formula 1 is used to calculate if the Boolean value is true, otherwise Formula 2 is used. Do not use the ? use the assignment operator after
Exercises: a man is considered overweight if his height minus his weight is less than 105, a woman is considered overweight if her height minus her weight is less than 110; gender (0 for woman, 1 for man), height height, weight weight. Use trinomial expressions.
gender ? height-weight<105:height-weight<110
Exercise: Write a program to get an integer between 0 and 127 from the keyboard and convert this integer to binary to display the result on the screen
implicit type conversion
If the expression contains a number of different types of numbers must first be converted to the same type and then in the calculation, this conversion process is called implicit type conversion, implicit type conversion is done entirely by the computer, implicit type conversion must be the occupation of a small area of the type of conversion into a large area of the type of different types of numbers of different types of different sizes on the integer type into a single-precision floating-point type, the signed type into an unsigned type of conversion. type into an unsigned type.
forced type conversion
A C program can temporarily assign a type to a number, which is called a forced type conversion, and the format of a forced type conversion is as follows
(char)300
Forced type conversion may result in loss of data content; type conversion does not modify the contents of the storage area.
branching statement
Branching statements can be selected from several groups of statements to execute a group and ignore the other groups, if you encounter a variety of possibilities when writing a program, each possibility requires a special statement to deal with the need to use branching; if keyword can be used to write branching statements, if branching needs to be written for each possibility of a special statement to deal with if branching needs to be prepared for each group of statements to write a pair of logical expressions, when the result of a logical expression is true, it will execute its paired statements. When a logical expression turns out to be true, the paired statement is executed.
if(){
}
else if(){
}
else if(){
}
else if(){
}
Any two statements in an if branch cannot be executed at the same time (statements that can be executed at the same time cannot be included in an if branch), it is best to determine the number of possibilities when writing an if branch, if there is bound to be a group of statements in the branch that will be executed then you can omit the last statement's logical expression and the if keyword. If more than one logical expression in the if branch is true then the statement corresponding to the first logical expression that is true will be executed and the subsequent statements will be ignored. If more than one logical expression in the if branch is true at the same time, the statement corresponding to the first true logical expression will be executed and the following statements will be ignored, which can be utilized to simplify the logical expressions in the if branch. a group of statements in the if branch is not only related to its paired logical expressions, but will only be executed if all the previous logical expressions are false and the paired logical expression is true. When writing if branches, try to keep the logical expressions simple and write them first.
Exercise: write a program to get three numbers from the keyboard, find the smallest of them and display it on the screen
The switch......case format can also be used to write branches, which can only be realized in the switch......case format if each possibility in a branch can be represented by a unique integer.
switch () {
case 0:
break;
case 1:
break;
case 2:
break;
case 4:
break;
default:
}