#include <stdio.h> int invert_end(int num,int bits); int main(void){ int number=0; int bit=0; int result=0; puts("Enter a number:"); scanf("%d",&number); puts("How many bits do you want to invert?:"); scanf("%d",&bit); result=invert_end(number,bit); printf("%d",result); } int invert_end(int num,int bits){ int mask=0; int bitval=1; while(bits-->0){ mask|=bitval; bitval<<=1; } return num^mask; }
本文转hackfreer51CTO博客,原文链接:http://blog.51cto.com/pnig0s1992/420990,如需转载请自行联系原作者