Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Translating binary to decimal numbers
#include<iostream> using namespace std; class number { private: int byte[8]; int sum; public: number() : sum(0) { } void binar() { for(int i=0;i<8;i++) { cin>>byte[i]; }} int btod() { if(byte[0]==1) sum+=128; if(byte[1]==1) sum+=64; if(byte[2]==1) sum+=32; if(byte[3]==1) sum+=16; if(byte[4]==1) sum+=8; if(byte[5]==1) sum+=4; if(byte[6]==1) sum+=2; if(byte[7]==1) sum+=1; return sum; } void decimal() { cout<<sum<<endl; } }; int main() { number s; s.binar(); s.btod(); s.decimal(); }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
Adress
KhadijahAlshehhi
Kadane's Algorithm
Game
Primality test Fermat primality test
execution of constructor and destructor
Minimum Vertices to Traverse Directed Graph
Network UVa
Undefined behavior
BreakfastMenu array
Please log in to post a comment.