Recent Posts - page 2
-
Clear till ith bit from MSB
This program is to clear all the bit starting from MSB till the ith bit Example: number = 224 : 1110 0001ith bit = 3Result= 1 : 0000 0001 Logic: For clearing say till 2nd bit, we need AND till… Read More ›
-
Clear till ith bit from LSB
This program is to clear all the bit starting from LSB till the ith bit Example: number = 7 : 0000 0111ith bit = 2Result= 4 : 0000 0100 Logic: For clearing say till 2nd bit, we need AND till… Read More ›
-
To find square of a number
This program is to find the square of a number. Logic: for even number: 4 * (n/2)^2 for odd number: 4 * (n/2)^2 + 4 * (n/2) + 1 (n/2) = (n >> 1) Output:
-
To set and clear a particular bit
This program is to set and clear a particular bit in a given number. The logic used will be: To set a particular bit: ORing the bit with 1 To clear the particular bit: ANDing the bit with 0. All… Read More ›
-
swap two random bits
This program is for swapping two random bits Output:
-
To swap two numbers
This program is to swap two numbers using XOR operator Output:
-
To toggle a number
This program is for toggling the complete number that is the set bit is to be cleared and clear bit has to be set. The logic would be using XORing each bit by 1. Example: num = 1001 0011mask =… Read More ›
-
To toggle a particular bit
This program is for toggling a particular bit that is if the bit is set clear and set it if it is clear. We will be using a Xor operator for doing so that is Xor that particular bit with… Read More ›
-
To test two numbers of opposite sign
This program is to find whether two numbers are of opposite sign. We will be using two approach to solve this: First approach:Simple Xor both the numbers and if result is less than 1 means the given two numbers are… Read More ›
-
To test whether a number is negative
This problem is to find whether a given number is negative or not The logic behind solving this problem is to get the MSB bit of a number and if its set means the given number is negative as MSB… Read More ›
Featured Categories
C Language ›
-
Swap odd-odd and even-even
September 12, 2021
-
Number power of 2
September 12, 2021
Operating system (OS) ›
-
Socket Options
June 6, 2021
-
Socket Programming
June 6, 2021
Networking ›
-
Virtual Extensible LAN(VXLAN)
May 16, 2021
-
Data Link Control- Framing
May 16, 2021