Author Archives
Aditya Prakash is a Sr. Software Engineer having 8+ yrs of experience with a strong emphasis on programming languages like C, C++, and Python on a Linux platform and worked on multiple products on Network Security and Telecom Domain.
He holds a degree in Computer Science Engineering and Diploma in Software System Development from CDAC, Bangalore and
also is a Cisco Certified Network Associate(CCNA) Certified Network Engineer.
LinkedIn :https://www.linkedin.com/in/aditya-prakash-2a84b140/
-
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 ›