Bit C language commands

Source: Internet
Author: User

Positions can be implemented using the OR operator "|:
Y = x | (1 <n );

Purge can be implemented with the operator:
Y = x &(~ (1 <n ));

The inversion can be implemented using the XOR operator "^:
Y = x ^ (1 <n );

Bit extraction operation:

Bit = (X | (1 <n)> N;

In general, bitwise operations are bitwise operations. Bit operations include
^ Exclusive or
| Bit or
& Bit and
~ Bitwise Inversion
> Right shift
<Left shift

The advantage of the bitwise operation is that the computation time and speed can be calculated directly based on the computation speed, which is basically the same as that of the Assembly.
Many bitwise operations are used directly to Express hardware computing or increase the computing speed.
For example, if the number is 16, the bitwise operation shifts four places to the left.

The other is bitfield.
It defines a special struct with only a specified number of members.
For example
Struct instruction {
Unsigned short SR: 5;
Unsigned short TR: 5;
Unsigned short OP: 6;
};
Defines the structure of a 16-bit command.
SR: TR: op
1-5: 6-10: 11-16
Then you can perform this operation.
Struct instruction mov_r1_r3 = {0x01, 0x03, 0x01 };
Then mov_r1_r3 is actually equal to 0x0461
This code is generally compiled to make it easy to use hardware interfaces and complete underlying operations.
The actual Code rarely appears, usually in interfaces with hardware.

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.