Operating system interview questions
Q.1) What is an operating system? A computer system has many resources which may be software or a hardware. A few of the common resources are CPU, files, different processes, memory etc. All these resources are managed by a low level software which is known as operating system. It acts as an interface between computer…
Extract k bits from p position
This program extracts k bits from given position say p Logic:1) right shift the number by p-12)set k bits Do and of 1 & 2 Same question can be asked to extract from say p to kthen p =p but k = k-p +1 Implementation: Output:
To find max and min of two number
This program is to find max and min of a given two numbers. Logic:result = b ^ ((a ^ b) & -(a < b)); // min(a, b) In above expression,if a < b, then -( a < b) become -1, so it behave like below expression result = b ^ ((a ^ b) & ~0);…
Swap odd-odd and even-even
This program is for swapping odd bits with its next odd bits and even bits with its next even bits LOGIC:If the two bits are different, just toggle them odd bit condition : i %2 ==0even bit condition : i %2 ==1as we start with index 0Example:Number 220 0 0 1 0 1 1 0Swap…
Swap even-odd bits of a number
This program is to swap Even and Odd position of a number. Logic:Get all the bits at the even position.And the number with 10 as 10 = 1 0 1 0Get all the bits at odd positionAnd the number by 5 = 0 1 0 1Now do left shift for even and right shift for…
Number power of 2
This program is to find out whether the given number is power of 2. Any number is power of 2 if (num & num -1) =0 Implementation: Output:
Check given number is power of 4
This program is to check whether a given number is power of 4 Condition for a number to be power of 4: If the number of bit set is 1The number of unset bit before the first set is even Example: number: 16 = 0001 0000Here number of bit set is 1 and clear bit…
Rotation of a number
This Program is to perform Right and Left rotate Operation What is rotation of a number by a bit? Rotation of a number by a particular bit can be: Left RotationRight Rotation Left Rotation:This means shifting all the bits to the left and pushing the dropped Most significant bit(MSB) to the Least significant bit(LSB). Right…
Change the endianess of a number
This program is to change the endianess of a number along with swapping the nibble of a byte Logic:1) data & 0x000000FF — This picks the first byte from a given number2) data & 0x0F) — This picks the first four bits of a byte After picking these we would shift them to their respective…
Reverse of a number
This program is to reverse a number Logic: Loop through all the bits of an integer.If a bit at ith position is set in the i/p no.then set the bit at (NO_OF_BITS – 1) – i in o/p.Where NO_OF_BITS is number of bits present in the given number. Output:
Loading…
Something went wrong. Please refresh the page and/or try again.
Follow My Blog
Get new content delivered directly to your inbox.