Created
January 28, 2013 01:57
-
-
Save pwittchen/4652232 to your computer and use it in GitHub Desktop.
Simple code snippet, which show how to convert binary number into decimal number very easily in C.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
int main(void) | |
{ | |
const char binary[] = "11001"; | |
int decimal = strtol(binary, NULL, 2); | |
printf("binary = \"%s\", decimal = %d = 0x%02X\n", | |
binary, decimal, decimal); | |
return 0; | |
} | |
/* my output | |
binary = "11001", decimal = 25 = 0x19 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment