/*
* bit_ops.c
* This program makes use of the various
bitwise operators.
*/
#include <stdio.h>
int main ()
{
int
a, b;
/* Read two
integer
numbers. */
printf
("Please enter two integer numbers: ");
scanf
("%d %d", &a, &b);
/* Print their
bitwise representation. */
printf
("a
=
%5d oct:
%011o hex: %08x\n",
a, a,
a);
printf
("b
=
%5d oct:
%011o hex: %08x\n\n",
b,
b, b);
/* Perform bitwise negation. */
printf
("~a =
%5d oct:
%011o hex: %08x\n",
~a,
~a, ~a);
printf
("~b =
%5d oct:
%011o hex: %08x\n\n",
~b,
~b, ~b);
/* Perform binary bitwise calculations. */
printf
("a & b = %5d
oct: %011o
hex: %08x\n", a&b, a&b, a&b);
printf
("a | b = %5d
oct: %011o
hex: %08x\n", a|b, a|b, a|b);
printf
("a ^ b = %5d
oct: %011o
hex: %08x\n\n", a^b, a^b, a^b);
/* Perform bitwise shifts. */
printf
("a << 1 = %5d
oct: %011o
hex: %08x\n", a<<1,
a<<1,
a<<1);
printf
("a >> 1 = %5d
oct: %011o
hex: %08x\n", a>>1,
a>>1,
a>>1);
printf
("b << 3 = %5d
oct: %011o
hex: %08x\n", b<<3,
b<<3,
b<<3);
printf
("b >> 3 = %5d
oct: %011o
hex: %08x\n", b>>3,
b>>3,
b>>3);
return
(0);
}