From 881fab49480212e754e25c4565798de77ccdf16e Mon Sep 17 00:00:00 2001 From: "Claudio J. Paz" Date: Wed, 30 Sep 2020 21:45:11 -0300 Subject: [PATCH] Add program-55 A bitwise operator program that prints a 32bit integer in binary representation --- C/program-55/program.c | 22 ++++++++++++++++++++++ C/program-55/read.md | 4 ++++ 2 files changed, 26 insertions(+) create mode 100644 C/program-55/program.c create mode 100644 C/program-55/read.md diff --git a/C/program-55/program.c b/C/program-55/program.c new file mode 100644 index 00000000..ff134113 --- /dev/null +++ b/C/program-55/program.c @@ -0,0 +1,22 @@ +/* Program that prints a number in binary*/ + +// start writng code from here +#include + +int main (void) +{ + int b; + unsigned int mask = 1<<31; + + printf("Input a 32bits integer number: "); + scanf("%d", &b); + + while (mask != 0){ + printf("%d", b&mask?1:0); + mask >>= 1; + } + + printf("\n"); + + return 0; +} diff --git a/C/program-55/read.md b/C/program-55/read.md new file mode 100644 index 00000000..42d8c087 --- /dev/null +++ b/C/program-55/read.md @@ -0,0 +1,4 @@ +# program-55 +## Program that prints a number in binary + +This program uses bitwise operators to print a 32bits integer in binary representation