Created
May 13, 2020 14:38
-
-
Save richardbowden/89f35f6d0f2a9e6effcf20ea2acb8815 to your computer and use it in GitHub Desktop.
string to binary
This file contains hidden or 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 <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