C Program to Convert Text String to Binary

String to Binary in C. str to binary in c. This page provides C programming solution to convert string to binary data or in other words a source program in C language to convert str to binary. Source program is given below with output.

Decimal TO Binary in C

Example: String to Binary in C

Here is the source code to convert text to binary in c.
#include <stdio.h>
#include <string.h>

int main(){
        int i;
        
        char *string = "String to Binary In C";
        
        for(i=0;i<8*strlen(string);i++)
            printf("%d",0 != (string[i/8] & 1 << (~i&7)));
            
        printf("\n");
}

Output:

010100110111010001110010011010010110111001100111001000000111010001101111001000000100001001101001011011100110000101110010011110010010000001001001011011100010000001000011

Comments