C examples for Function:Utility Function
Create a function to invert bit from an integer
#include <stdio.h> unsigned invert(unsigned x, int p, int n) { // 000001111100000 unsigned mask = ~(~0U << n) << (p + 1 - n); // xxxxx^^^^^xxxxx return x ^ mask; } int main(void) { printf("%u\n", invert(5432, 6, 3)); return 0;// w ww . j ava2s. c o m }