C # basic usage of bitwise operators,
Bitwise operators include: | bitwise OR, & bitwise AND, ^ bitwise xor or xor ,~ NOT, Right Shift, and so on. This article describes the application of the bitwise operator in C. It mainly includes:
○
Bitwise operators include: | bitwise OR or, & bitwise AND and, ^ bitwise XOR or XOR ,~ Not, right shift, and so on. This article describes the application of the bitwise operator in C. It mainly includes:
○ Hexadecimal conversion※Convert
In practice, the value of some variables is limited to a limited range. For example, there are only seven days in a week, 12 months in a year, and six courses per week in a class. It is obviously inappropriate to describe these values as integer,
I. Six operators in C language:
& Bitwise AND
| By bit or
^ Bitwise OR
~ Invert
> Right shift
1. bitwise AND OPERATION
Bitwise AND operator "&" are binary operators.
Its function is the binary phase corresponding to the two numbers involved in the
Analysis on the Application of JavaScript bitwise operators
Next, let's talk about the bit operations in js (also applicable to other languages) based on your own cognition. If there are any errors, please correct me.
Most languages provide bitwise
Next, let's talk about the bit operations in js (also applicable to other languages) based on your own cognition. If there is an error, please note that most languages provide bitwise operators, bitwise operators are widely used in c, c ++, and
K&r Exercise 2-6,setbits (x,p,n,y), set the n bits from the p bit in x to the rightmost n-bit value in Y, and the rest of the x remain unchanged. #include unsigned setbits (unsigned x, int p, int n,unsigned y) { int mask; int pos=p+1-n;
I still don't like bitwise operations... Ah...
I just saw a post about a netizen's bitwise operation reversing one byte on the Internet and posted it to learn to accumulate...Code:
UnsignedCharReverse8 (unsignedCharC){C = (C &0x55) 1| (C &0xaa)>1
The bitwise inverse operator is reversed by each bit of the binary, such as the byte type, and the result of ~0 is 255.This function can do some reversal operation in maskThe following code, a contains three values of 2,4,8. Invert with bitwise
Bitwise operations are binary operations. In system software, binary bitwise is often required. The C language provides six operations
Operator. These operators can only be used for integer operands, that is, they can only be used for signed or
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.