Last active
January 2, 2016 19:09
-
-
Save VardanGrigoryan/8348535 to your computer and use it in GitHub Desktop.
ASCII character to binary code
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> | |
int main() | |
{ | |
int a[8]; | |
const char c = 'a'; | |
for(unsigned int i = 0; i < sizeof(char)*8; ++i) | |
{ | |
if(c & (1 << i)) | |
{ | |
a[i] = 1; | |
} | |
else | |
{ | |
a[i] = 0; | |
} | |
} | |
std::cout << "the ascii character binary code is: " << std::endl; | |
for(int i = 0; i < 8; ++i) | |
{ | |
std::cout << " " << a[i] << " "; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment