Skip to content

Instantly share code, notes, and snippets.

@VardanGrigoryan
Last active January 2, 2016 19:09
Show Gist options
  • Save VardanGrigoryan/8348535 to your computer and use it in GitHub Desktop.
Save VardanGrigoryan/8348535 to your computer and use it in GitHub Desktop.
ASCII character to binary code
#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