Last active
August 29, 2015 14:06
-
-
Save yousefamar/84742f8e57632a94465c to your computer and use it in GitHub Desktop.
A small program that prints integers in binary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
bool bitTest(unsigned int num, int bit) { | |
return ((1<<bit)&num)>0; | |
} | |
void printBin(unsigned int num) { | |
int i; | |
cout << num <<" in binary is: "; | |
for(i=8; i>=0; i--) { | |
if(bitTest(num, i)) | |
cout << "1"; | |
else | |
cout << "0"; | |
} | |
cout << endl; | |
} | |
void main() { | |
printBin(10); | |
printBin('A'); | |
printBin('M'); | |
printBin('A'); | |
printBin('R'); | |
printBin(163); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment