0% found this document useful (0 votes)
255 views2 pages

1.bitwise Operators

The document provides examples of bitwise operations and programs to perform operations on bits of numbers such as setting, clearing, and toggling bits, determining if a number is even, odd, positive or negative, swapping two numbers, checking if a number is a power of 2, rotating bits, converting case of characters, reversing bits, comparing numbers with bitwise operators, manipulating bits of floating point numbers, swapping bytes of a hexadecimal number, deleting bits from a position, swapping nibbles, extracting bits, and clearing a bit. It also provides an example of storing 48 bits in a character buffer and transferring to integer variables.

Uploaded by

Paul kollam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
255 views2 pages

1.bitwise Operators

The document provides examples of bitwise operations and programs to perform operations on bits of numbers such as setting, clearing, and toggling bits, determining if a number is even, odd, positive or negative, swapping two numbers, checking if a number is a power of 2, rotating bits, converting case of characters, reversing bits, comparing numbers with bitwise operators, manipulating bits of floating point numbers, swapping bytes of a hexadecimal number, deleting bits from a position, swapping nibbles, extracting bits, and clearing a bit. It also provides an example of storing 48 bits in a character buffer and transferring to integer variables.

Uploaded by

Paul kollam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Bitwise Operators

---------------------------------------------------------------------------------------------------------------
1. Write a program for the following one.
a) Set a bit b) Clear a bit c) Toggle a bit

2. WAP to find the given number is even or odd using bitwise operators.

3. WAP to find the given number is +ve or -ve using bitwise operators.

4. WAP to swap two numbers using bitwise operators.

5. WAP to find the given number is power of 2 or not.

6. WAP to find the given number is divisble by 8 or not using bitwise operators.

7. Write a program to rotate the bits. Input the no.of rotations, at runtime.
Ex : binary : 10000000000000000000000000001011
rotations : suppose 3 times right, then
result : 01110000000000000000000000000001

binary : 10000000000000000000000000001011
rotations : suppose 4 times left, then
result : 00000000000000000000000010111000

8. Convert the characters Upper to Lower and Lower to Upper using bitwise
operators.

9. Write a program to reverse the bits of a given number.


Note : not just reverse printing.

10. Write a one line code to compare two numbers using bitwise operators.

11. Write a program to print float binay formation using char *ptr.

12. Write a program to swap the adjucent bytes of a given 4-digit hexadecimal
number.
Ex : given number = 0x1234;
after swap : 0x3412;

13. Write a program to delete no.of bits from perticular position in a given number.
Input the no.of bits, at runtime.
Ex: Suppose num = 100;
It's Binaray is 00000000000000000000000001100100
delete 2 bits from 4th position
then result is 00000000000000000000000000011100

14. Write a macro for swapping first and last nibbles in a given integer.
Ex: Suppose num = 10

It's Binary is 0000000000000000000000000001010


After swap 1010000000000000000000000000000

15. Write a logic to extract P bits from Posion N in an integer M

16. Write a macro to clear a bit at the position N in an integer M.

17. There are 48 bits are stored in an array of character buffer and store them into 2
integer variables.

-------------------------------------------------------- END --------------------------------------------------------

Dear Students, if any mistakes found, Kindly inform to me.

A.Tandava Ramakrishna
Email: [email protected]

You might also like