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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

read out MAC-Adresse + hex to string, string to hex

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hello
I have two questions.
1. How can I read out a MAC-Address from a Network Interface card?
2. I read a hexadecimal figure from a file into an Array of char(String). I want to increment
the hex- figure. Afterwards I have to write the hexadecimal figure into a file.
My question: How can I convert a String into a hexadecimal figure and the other way around?
Thank you for your help
 
As to the 1st question, this is quite operating system dependent, so nobody can reasonably help you without more details about your environment. Furthermore, it's not really a C question, so you might have better luck asking in a forum dedicated to your system.

For the 2nd question, use strtol() or strtoul() to convert the string representation of the hex number to decimal:

#include <stdio.h>
#include <stdlib.h>

/* ... */

char hex[]=&quot;0x1bcd34&quot;;
char buf[100]; /* arbitrary limit of 100 */

unsigned num=(unsigned)strtol(hex,NULL,16);

/* use sprintf() to convert it back */

sprintf(buf,&quot;%X&quot;,&num);

HTH,

Russ
bobbitts@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top