Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Binary to Integer (C)
// 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); }
run
|
edit
|
history
|
help
1
Area and Volume coding
Lab 7 blackjack v0.1
C_141113_VariosPerfectos
G
garbage
AVANCE DE PREGUNTA 5
Matriz funcona medio raor aslñdk
5 trabajo semanal 4
Vowel Assignment
C code to compare two texts in form of array of chars ignoring the capitalization