-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
21077b3
commit bc8f47a
Showing
99 changed files
with
6,141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include<stdio.h> | ||
#include<stdbool.h> | ||
|
||
//12th Bit | ||
|
||
typedef unsigned int UINT; | ||
|
||
// 0000 0000 0000 0000 0000 0000 0000 0000 | ||
|
||
// 1111 1111 1111 1111 1111 1111 1111 0111 | ||
|
||
// F F F F F F F F | ||
|
||
// FFFFFFFF7 | ||
// 0XFFFFFFFF7 | ||
|
||
UINT OffBit(UINT No) | ||
{ | ||
UINT iMask = 0XFFFFFFF7; | ||
|
||
return (No & iMask); | ||
} | ||
|
||
int main() | ||
{ | ||
UINT Value = 0; | ||
UINT iRet = 0; | ||
|
||
printf("Enter number : \n"); | ||
scanf("%d",&Value); | ||
|
||
iRet = OffBit(Value); | ||
|
||
printf("Updated number is : %d\n",iRet); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include<stdio.h> | ||
#include<stdbool.h> | ||
|
||
//12th Bit | ||
|
||
typedef unsigned int UINT; | ||
|
||
// 0000 0000 0000 0000 0000 0000 0000 0000 | ||
|
||
// 1111 1111 1111 1111 1111 1111 1111 0111 | ||
|
||
// F F F F F F F F | ||
|
||
// FFFFFFFF7 | ||
// 0XFFFFFFFF7 | ||
|
||
UINT OffBit(UINT No) | ||
{ | ||
UINT iMask = 0XFFFFFFF7; | ||
UINT iAns = 0; | ||
|
||
iAns = No & iMask; | ||
|
||
return iAns; | ||
} | ||
|
||
int main() | ||
{ | ||
UINT Value = 0; | ||
UINT iRet = 0; | ||
|
||
printf("Enter number : \n"); | ||
scanf("%d",&Value); | ||
|
||
iRet = OffBit(Value); | ||
|
||
printf("Updated number is : %d\n",iRet); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include<stdio.h> | ||
#include<stdbool.h> | ||
|
||
//4th Bit | ||
|
||
typedef unsigned int UINT; | ||
|
||
// 0000 0000 0000 0000 0000 0000 0000 0000 | ||
|
||
// 0000 0000 0000 0000 0000 0000 0000 1000 | ||
|
||
UINT ToggleBit(UINT No) | ||
{ | ||
UINT iMask = 0X00000008; | ||
UINT iAns = 0; | ||
|
||
iAns = No ^ iMask; | ||
|
||
return iAns; | ||
} | ||
|
||
int main() | ||
{ | ||
UINT Value = 0; | ||
UINT iRet = 0; | ||
|
||
printf("Enter number : \n"); | ||
scanf("%d",&Value); | ||
|
||
iRet = ToggleBit(Value); | ||
|
||
printf("Updated number is : %d\n",iRet); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include<stdio.h> | ||
#include<stdbool.h> | ||
|
||
//5,6,7th Bit | ||
|
||
typedef unsigned int UINT; | ||
|
||
// 0000 0000 0000 0000 0000 0000 0000 0000 | ||
|
||
// 0000 0000 0000 0000 0000 0000 0111 000 | ||
|
||
UINT ToggleBit(UINT No) | ||
{ | ||
UINT iMask = 0X00000070; | ||
UINT iAns = 0; | ||
|
||
iAns = No ^ iMask; | ||
|
||
return iAns; | ||
} | ||
|
||
int main() | ||
{ | ||
UINT Value = 0; | ||
UINT iRet = 0; | ||
|
||
printf("Enter number : \n"); | ||
scanf("%d",&Value); | ||
|
||
iRet = ToggleBit(Value); | ||
|
||
printf("Updated number is : %d\n",iRet); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include<stdio.h> | ||
#include<stdbool.h> | ||
|
||
typedef unsigned int UINT; | ||
|
||
bool CheckBit(UINT No, UINT Pos) | ||
{ | ||
UINT iMask = 0X00000001; // UINT iMask = 1; | ||
UINT Result = 0; | ||
|
||
if((Pos < 1) || (Pos > 32)) | ||
{ | ||
printf("Invalid position, it should between 1 to 32\n"); | ||
return false; | ||
} | ||
|
||
iMask = iMask << (Pos -1); // Dynamic Mask Formation | ||
|
||
Result = No & iMask; | ||
|
||
if(Result == iMask) | ||
{ | ||
return true; | ||
} | ||
else | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
int main() | ||
{ | ||
UINT Value = 0; | ||
UINT Position = 0; | ||
bool bRet = false; | ||
|
||
printf("Enter number : \n"); | ||
scanf("%d",&Value); | ||
|
||
printf("Enter the position of bit\n"); | ||
scanf("%d",&Position); | ||
|
||
bRet = CheckBit(Value,Position); | ||
|
||
if(bRet == true) | ||
{ | ||
printf("Bit at the position %d is ON\n",Position); | ||
} | ||
else | ||
{ | ||
printf("Bit at the position %d is OFF\n",Position); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#include<stdio.h> | ||
#include<stdbool.h> | ||
|
||
typedef unsigned int UINT; | ||
|
||
bool CheckBit(UINT No, UINT Pos1 , UINT Pos2) | ||
{ | ||
UINT iMask1 = 0X00000001; // UINT iMask = 1; | ||
UINT iMask2 = 0X00000001; | ||
|
||
UINT iMask = 0; | ||
|
||
UINT Result = 0; | ||
|
||
if((Pos1 < 1) || (Pos1 > 32) || (Pos2 < 1) || (Pos2 > 32)) | ||
{ | ||
printf("Invalid position, it should between 1 to 32\n"); | ||
return false; | ||
} | ||
|
||
iMask1 = iMask1 << (Pos1 -1); // Dynamic Mask Formation | ||
iMask2 = iMask2 << (Pos2 -1); // Dynamic Mask Formation | ||
|
||
iMask = iMask1 | iMask2; | ||
|
||
Result = No & iMask; | ||
|
||
if(Result == iMask) | ||
{ | ||
return true; | ||
} | ||
else | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
int main() | ||
{ | ||
UINT Value = 0; | ||
UINT Position1 = 0; | ||
UINT Position2 = 0; | ||
|
||
bool bRet = false; | ||
|
||
printf("Enter number : \n"); | ||
scanf("%d",&Value); | ||
|
||
printf("Enter the position of bit\n"); | ||
scanf("%d",&Position1); | ||
|
||
printf("Enter the position of bit\n"); | ||
scanf("%d",&Position2); | ||
|
||
bRet = CheckBit(Value,Position1,Position2); | ||
|
||
if(bRet == true) | ||
{ | ||
printf("Bit at the position %d & %d is ON\n",Position1,Position2); | ||
} | ||
else | ||
{ | ||
printf("Bit at the position %d & %d is OFF\n",Position1,Position2); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include<stdio.h> | ||
#include<stdbool.h> | ||
|
||
typedef unsigned int UINT; | ||
|
||
// 0000 1111 0000 1111 0000 1111 0000 1111 | ||
// 0 F 0 F 0 F 0 F | ||
|
||
//0X0F0F0F0F | ||
|
||
UINT ToggleBit(UINT No) | ||
{ | ||
UINT iMask = 0X0F0F0F0F; | ||
UINT iAns = 0; | ||
|
||
iAns = No ^ iMask; | ||
|
||
return iAns; | ||
} | ||
|
||
int main() | ||
{ | ||
UINT Value = 0; | ||
UINT iRet = 0; | ||
|
||
printf("Enter number : \n"); | ||
scanf("%d",&Value); | ||
|
||
iRet = ToggleBit(Value); | ||
|
||
printf("Updated number is : %d\n",iRet); | ||
|
||
return 0; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
//No 1 0 1 1 0 0 0 1 | ||
|
||
// Mask 1 1 1 1 0 1 1 1 | ||
|
||
// -------------------------------------------------------- | ||
|
||
// Result 1 0 1 1 0 0 0 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include<stdio.h> | ||
#include<stdbool.h> | ||
|
||
typedef unsigned int UINT; | ||
|
||
UINT OffBit(UINT No, UINT Pos) | ||
{ | ||
UINT iMask = 0X00000001; | ||
UINT Result = 0; | ||
|
||
iMask = iMask << (Pos-1); | ||
|
||
iMask = ~iMask; | ||
|
||
Result = No & iMask; | ||
|
||
return Result; | ||
} | ||
|
||
int main() | ||
{ | ||
UINT Value = 0, Position = 0; | ||
UINT iRet = 0; | ||
|
||
printf("Enter number : \n"); | ||
scanf("%d",&Value); | ||
|
||
printf("Enter the position : \n"); | ||
scanf("%d",&Position); | ||
|
||
iRet = OffBit(Value,Position); | ||
|
||
printf("Updated number is : %d\n",iRet); | ||
|
||
return 0; | ||
} | ||
|
||
|
||
/* | ||
No = 1 0 1 0 1 1 1 0 | ||
Pos = 6 | ||
iMask = 0 0 0 0 0 0 0 1 | ||
iMask = iMask << (5) | ||
iMask = 0 0 1 0 0 0 0 0 | ||
iMask = ~iMask; | ||
iMask = 1 1 0 1 1 1 1 1 | ||
iNo 1 0 1 0 1 1 1 0 | ||
iMask 1 1 0 1 1 1 1 1 & | ||
---------------------------------- | ||
Result 1 0 0 0 1 1 1 0 | ||
*/ | ||
|
||
|
||
|
||
|
||
// 1 1 1 1 1 1 1 0 |
Oops, something went wrong.