C/C++: Converting hexadecimal value in char to integer

前端 未结 7 1620
萌比男神i
萌比男神i 2021-01-01 06:28

I have hexadecimal values stored as characters:

char A = \'0\';
char B = \'6\';
char C = \'E\';

... I need them coverted to integers. I kno

7条回答
  •  鱼传尺愫
    2021-01-01 06:31

    You could try strtol. But strtol needs a 0 terminated char *, so:

    long x = strtol((char[]){A, 0}, NULL, 16);
    

提交回复
热议问题