I just learning C. Could someone explain that what are they using for ? these operators. in a real industrial case..thanks.
like:
when I need these? :
~X
n = n & 0177
x = x | 1211
Please tell me.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is fundamental and so there are many potential applications, but here’s a specific industrial example:
Suppose you’re sending a bunch of command and/or status info between devices. To avoid wasting bandwidth (particularly if you’re using a slower type of connection such an old 9-pin serial connection, which are still used on industrial devices), you very well may “pack” and “unpack” the data. In the case of two-state signals, this means that each byte can hold up to eight independent statuses. To get the status of bit 6, you could do something like this:
In the above line, 0x40 is a bitmask that results in all bits being zero except for bit 6. The shift right by 6 converts the resulting value–0x40 or 0x00–to 1 or 0.
Take a look at this brief section for standard, related examples: Bit Manipulation in C