Skip to content

Instantly share code, notes, and snippets.

@yousefamar
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yousefamar/84742f8e57632a94465c to your computer and use it in GitHub Desktop.
Save yousefamar/84742f8e57632a94465c to your computer and use it in GitHub Desktop.
A small program that prints integers in binary
#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