Skip to content

Convert Your Love letter to Binary, Even Your GF can't Understand

Notifications You must be signed in to change notification settings

naemazam/Word-to-Binary-Convert

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

Word to Binary Convert

Convert Your Loveletter to Binary

Simple Knowledge

A binary number is a number expressed in the base-2 numeral system or binary numeral system, a method of mathematical expression which uses only two symbols: typically "0" and "1". The base-2 numeral system is a positional notation with a radix of 2. Each digit is referred to as a bit, or binary digit.

CPP Code

Copy code and test on Any Editor

#include <bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    cin>>a;
    for(int i=0;i<int(a.size());i++)
    {
    
        //convert each character to its decimal representation
        int b=int(a[i]);
        vector<int> c;
        
        //convert from dec to bin
        while(b!=0)
        {
            c.push_back(b%2);
            b/=2;
        }
        
        //Input characters
        cout<<a[i]<<" = ";
        
        //completing the missing bits
        for(int j=0;j<int(8-c.size());j++)
            cout<<0;
        
        //the output
        for(int j=c.size()-1;j>=0;j--)
            cout<<c[j];
        cout<<"\n";
    }
    cout<<"\nConvert completed..";
    return 0;
}

Demo Output

a = 01100001
z = 01111010
a = 01100001
m = 01101101

Convert completed..

Contributing

Contributions are always welcome!

About

Convert Your Love letter to Binary, Even Your GF can't Understand

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published