Posts

Showing posts from March, 2015

Bit Operations in C

The following program explains four basic bit operations. Set a Bit Clear a Bit Toggle a Bit Test a Bit Print the integer in bit format More Functions GitHub :  https://github.com/vaneeswaran/my_c_codes/blob/master/bit_operations/Macro%20Functions%20%26%20Bit%20Operations.c <#Read Me: Developed By: Name:Vaneeswaran N www.vaneeswaran.com #> /* The following program is the sample for bit operation //Header File Declaration #include<stdio.h> #include<string.h> //Macro Definition #define SET_BIT(ipb,n) (ipb|= 1 << n) //ipb is the input byte and n is the position #define CLR_BIT(ipb,n) (ipb &= ~(1<<n)) #define TOG_BIT(ipb,n) (ipb^= 1 << n) #define TEST_BIT(ipb,n) (ipb&=(1<<n)) void print_byte( unsigned int input) { int i; printf( "\nBinary Form:" ); for (i = 0 ; i < 32 ; i++) printf( "%d" ,(((input << i) &