Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Binary to Integer (C)
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
// Author: Ice Scripter /* Inspired by the dude who made Binary to Integers / Integers to Binary in lua https://rextester.com/discussion/HTUOX30484/ NOTES: I will probably update this and make my own exp func to eliminate the math library I will also update this to have both b2i and i2b like that one guy I also plan on making this an actual function and not just running in the main func */ #include <stdio.h> #include <math.h> // Didn't want to use an extra library but I didn't want to make my own exp func lol // Make sure to add "-lm" in your compiler arguments since this library is in use. int main() { const unsigned int SIZE_OF_BYTE = 8; char input[8] = "00001101"; unsigned int output = 0; for (int i = SIZE_OF_BYTE-1; i >= 0; i--) { output += (int) (input[i]-48) * ( pow (2, ((i- (SIZE_OF_BYTE-1) )*-1) )); } printf("Output: %d", output); }
gcc
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
Compilation time: 0.13 sec, absolute running time: 0.17 sec, cpu time: 0.01 sec, memory peak: 6 Mb, absolute service time: 0,47 sec
edit mode
|
history
|
discussion
Output: 13