Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Bit_manipulation/Addition_using_bits.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include<stdio.h>

//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;

}
15 changes: 15 additions & 0 deletions Bit_manipulation/Byte_Swapper.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* C program to swap bytes/words of integer number.*/

#include <stdio.h>

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;
}