How to convert hex number to separated decimal numbers in C

1 Answer

0 votes
#include <stdio.h>
#include <string.h> 
  
int main(void)
{
    char hex[30] = "47C5EA3";
    int i; 

    printf("hex = %s \n", hex);
    for (i = 0; i < strlen(hex); i++) 
    { 
        printf("%c = %d\n", hex[i], (hex[i] >= 'A') ? (hex[i] - 'A' + 10 ) : (hex[i] - '0'));
    } 
         
    return 0;
}

  
/*
 
run:
 
hex = 47C5EA3
4 = 4
7 = 7
C = 12
5 = 5
E = 14
A = 10
3 = 3
 
*/


answered Feb 12, 2015 by avibootz

Related questions

1 answer 383 views
1 answer 248 views
1 answer 261 views
1 answer 271 views
2 answers 257 views
257 views asked Jun 5, 2022 by avibootz
...