Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert char* eg. "0x1A" to char* 0x1A (hexadecimal) 1

Status
Not open for further replies.

diaglez

Technical User
Jun 20, 2006
18
ES
Hi, I have the following:

char myvar[4] = "0x3B"
unsigned char mac[6];
mac[0] = 0x1A;
mac[1] = 0x22;
....

the question is how can I do this new assignment:

mac[2] = content of myvar[4];

but it has to be stored it in the same format that mac[1] = 0x1A (hexadecimal)

thx.
 
Would strtol() work with a hex number, or if it starts with "0x"?
I know sscanf() would work.
 
thx a lot xwb and cpjust. Finally cpjust's solution did the trick. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top