Skip to content

Instantly share code, notes, and snippets.

@richardbowden
Created May 13, 2020 14:38
Show Gist options
  • Select an option

  • Save richardbowden/89f35f6d0f2a9e6effcf20ea2acb8815 to your computer and use it in GitHub Desktop.

Select an option

Save richardbowden/89f35f6d0f2a9e6effcf20ea2acb8815 to your computer and use it in GitHub Desktop.
string to binary
#include <stdio.h>
#include <string.h>
int main()
{
char *string = "hello, world!";
size_t len = strlen(string);
int divide;
for (size_t i = 0; i < len; i++)
{
divide = string[i];
for (int i = 7; i >= 0; i--){
int k = divide >> i;
if (k & 1){
printf("1");
}else{
printf("0");
}
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment