Bitwise operation and Flow Control Statement 5

Source: Internet
Author: User
Tags switch case

File naming method: camper name classnum
Underline name class_num

A 65 Z 90
A 97 Z 122

 

Baxuexi de Zuo Cheng Biji
Bu Yao Wangji Mei Tian Fuxi Qianyi Tian Xue Xi de.
Wen Gu er Zhi Xin Bu Jiu Geng You Yi si le ma.

I. bitwise operations

Symbol description calculation rules
& Bitwise AND shielding some binary bits (set to zero)

| Either Anwei or both of them have zero results.
Purpose: set some binary bits to 1.
You can determine whether a binary is 1 or 0.


^ Bitwise OR two identical values are 0 and different values are 1
Role: it can be used to reverse the finger position


~ Change the value from 0 to 0.
~ 0000 1111 = 1111 0000
<Left shift: shifts the binary digits left in sequence,
High Discard, low zero fill (left shift is equivalent

0000 1111 <2 = 0011 1100
> Shifted right: all binary digits shifted right: Several digits
For zero completion with a high number of unsigned values,
For the number of symbols for the number of symbols, depending on the Compiler
, Some complement signs, which are called arithmetic shift right,
Some high-position zeros (logical right shift)

Logical shift B> 3;
Parity: the result of division by two integers (touch) is an even number. Otherwise, the result is an odd number.
Compare float X with 0
Float F = 0.000001;
If (x <= F & x> = f)
{
}
Two variables are exchanged without the third variable.
A = a ^ B;
B = B ^ A; // B = B ^ (a ^ B) B = B ^ A B = 0 ^ a B =
A = a ^ B; // A = (a ^ B) ^ (B ^ A) = (a ^ B) ^ (B ^ (a ^ B )) = B // Exchange Rate
Equivalent to the following formula
A1 = a ^ B;
B1 = B ^ A1;
A2 = A1 ^ B1;
:! Run the following command with an exclamation mark :! GCC day01.c

2. Process Control statements


It can be divided into conditional statements, switch statements, and cyclic statements.
(1) condition statements
If (expression) {compound statement };
If (expression) statement;
If (expression)
Statement 1;
Else if (expression)
Statement 2;
Else if (expression)
Statement 3;
Else
Statement 4;
1. Else if each has 0 to n
2. Else can have 0 to 1
3. If there is only one branch statement, you can omit {}
Printf ("the larger number is: % d \ n", a> = B? A: B );
// Do not forget to write % d \ n Buran without any results
Scanf ("% d \ n", a, B); // The \ n in the middle cannot be added, and an error is returned.

(2) switch statement


1 .? : // Three-object Operator
2. Switch case
Switch (expression ){
Case constant expression: Statement 1;
Case constant expression: Statement 2; break;
....
Case constant expression: Statement N; break;
Default:
Statement;
}
Note:
1. expression. The calculation result must be an integer, not a floating point or string.
2. For constant expressions that cannot contain variables or function calls,
The final result should be an integer.
3. Each branch can have multiple statements to terminate with a break. No need to add {}
4. Duplicate branches are not allowed.
Exercise: Enter the month to print the number of days of the month?
5. The break keyword jumps out or ends.
Enter the year, month, and day to calculate the day of the year.
Goto
Break: Jump out or loop (branch switch)
Continue: continue. Terminate this cycle and enter the next cycle


Print the number between 1 and 30 that cannot be divided by four


While loop do while: WHILE LOOP
While (expression condition) {statement ;}

While (1); equivalent to for (;) infinite loop
Do {statement block, multiple statements} while (); Do not forget the last semicolon

Exercise: complete the days. C code with verification
2. Enter five Integers to find the largest
3. Use do while to determine the number of digits in an integer
4. Question: enter an integer to print the binary


2. Enter five numbers
Scanf
A> B
A> C
A <d

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.