diff --git a/Bit_manipulation/Addition_using_bits.c b/Bit_manipulation/Addition_using_bits.c new file mode 100644 index 0000000000..744a05910d --- /dev/null +++ b/Bit_manipulation/Addition_using_bits.c @@ -0,0 +1,26 @@ +#include + +//this is a function which will execute addition using bits +int add_bits(int value1, int value2) +{ + unsigned int carry = value1 & value2; + unsigned int sum = value1 ^ value2; + + while(carry != 0) + { + unsigned int shiftedcarry = carry << 1; + carry = sum & shiftedcarry; + sum ^= shiftedcarry; + } + + return sum; + +} + +int main(void) +{ + printf("%d\n",add_bits(55,10)); + + return 0; + +} diff --git a/Bit_manipulation/Byte_Swapper.c b/Bit_manipulation/Byte_Swapper.c new file mode 100644 index 0000000000..f9b9f8b71a --- /dev/null +++ b/Bit_manipulation/Byte_Swapper.c @@ -0,0 +1,15 @@ +/* C program to swap bytes/words of integer number.*/ + +#include + +int main() +{ + unsigned int data = 0x1234; + printf("\ndata before swapping : %04X", data); + + data = ((data << 8) & 0xff00) | ((data >> 8) & 0x00ff); + + printf("\ndata after swapping : %04X \n", data); + + return 0; +}