Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple code snippet, which show how to convert binary number into decimal number very easily in C.
#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