How to convert hexadecimal string to int number in C

2 Answers

0 votes
#include <stdio.h>
#include <stdlib.h>
  
int main() 
{ 
	char s[] = "0x1A"; 
	
    int n = (int)strtol(s, NULL, 16);
	
	printf("%d\n", n);
	
    return 0; 
}



/*
run:

26

*/

 



answered Oct 15, 2019 by avibootz
0 votes
#include <stdio.h>
#include <inttypes.h>
   
int main() 
{ 
    char s[] = "0x1A"; 
     
    int n = strtoimax(s, NULL, 16);
     
    printf("%d\n", n);
     
    return 0; 
}
 
 
 
/*
run:
 
26
 
*/

 



answered Oct 15, 2019 by avibootz

Related questions

1 answer 160 views
160 views asked Sep 18, 2021 by avibootz
1 answer 185 views
185 views asked Sep 18, 2021 by avibootz
1 answer 189 views
1 answer 191 views
1 answer 168 views
...