Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Translating binary to decimal numbers
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
#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(); }
g++
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
edit mode
|
history
|
discussion