Skip to content

Instantly share code, notes, and snippets.

@pwittchen
Created January 28, 2013 01:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pwittchen/4652232 to your computer and use it in GitHub Desktop.
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.
#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