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
MATRIZ DE CADENAS
A_141211_Tartaglia
main.c
Day 2 String Manipulation
A_141121_factorial02
Exm
ayudantia 1 mod 4
TopTriangle.c
mapOfIndia
Project 3 Part 1 v1.7