"& Gt;" and "& amp;" operators in c

Source: Internet
Author: User
Tags bitwise operators

">" And "&" operators in c
In c, the median operators include: And, Or, XOR, inversion, left shifting, and right shifting. bitwise operators are binary operators. The right shift operator is to move the binary digits of a number to the right n places, and the low digits of the right side are discarded. For the unsigned number, the high position is supplemented with 0, that is, in decimal format, each right shift is equivalent to dividing by 2, for example, a: 10101010 01010101 a> 10010101. For a signed number, some machines fill the blank part on the left with a signed bit, but some machines fill the blank part on the left with 0. For example, a: 11100111 00011101 a> 1110011 10001110 or 11110011 10001110. Source code in c: write the number 15 after the conversion to binary 1. # Include <stdio. h> int main () {int a = 15; int count = 0; while (a) {if (a % 2 = 1) count ++; a = a> 1;} printf ("% d", count); return 0;} result: 4 and operator: bitwise AND operator & is often used to block some binary bits. For example, a: 1001 0111 B: 1111 0000 a & B: 1001 0000 c program inputs a number into the number 1 after binary conversion. # Include <stdio. h> int main () {int count = 0; int num; scanf ("% d", & num); while (num) {count ++; num = num & (num-1);} printf ("% d \ n", count); return 0;} result: 4

Related Article

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.