#include "math.h" #include "stdio.h" /////////////////////////////////////////////////////////////// // The bits arg represents the bit say:8,16,32... ///////////////////////////////////////////////////////////// volatile long Hex_To_Int(long Hex,char bits) { long Hex_2_Int; char byte; Hex_2_Int=0; for(byte=0;byte<bits;byte++) { if(Hex&(0x0001<<byte)) Hex_2_Int+=1*(pow(2,byte)); else Hex_2_Int+=0*(pow(2,byte)); } return Hex_2_Int; } /////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////// void main (void) { int Dec; char Hex=0xFA; Dec= Hex_To_Int(Hex,8); //convert an 8-bis hexadecimal value to a number in base 10 printf("the number is %d",Dec); }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter