Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
vaibhavpatilX authored Jun 22, 2024
1 parent 21077b3 commit bc8f47a
Show file tree
Hide file tree
Showing 99 changed files with 6,141 additions and 0 deletions.
37 changes: 37 additions & 0 deletions Program337.c
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;
}
40 changes: 40 additions & 0 deletions Program338.c
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;
}
35 changes: 35 additions & 0 deletions Program339.c
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;
}
35 changes: 35 additions & 0 deletions Program340.c
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;
}
54 changes: 54 additions & 0 deletions Program341.c
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;
}
66 changes: 66 additions & 0 deletions Program342.c
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;
}
46 changes: 46 additions & 0 deletions Program343.c
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
63 changes: 63 additions & 0 deletions Program344.c
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
Loading

0 comments on commit bc8f47a

Please sign in to comment.