Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define sz(x) int(x.size())
- #define nl "\n"
- void octalToBin(){
- string num ;
- cout <<"Enter the number in octal to convert it to binary : " ;
- cin >> num;
- vector < string > convert{"000" , "001" , "010" , "011" , "100" , "101" , "110" , "111" };
- string ans ="";
- for(int i = 0; i < num.size() ; i++){
- if(num[i]=='.')
- ans+='.';
- else if(num[i] >='0' and num[i] <='7')
- ans+=convert[num[i]-'0'] ;
- else
- return void(cout <<"Cann't be convert this number. "<< nl);
- }
- cout <<"Binary number : "<< ans << nl;
- }
- int main() {
- octalToBin();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement