There is a string representing the hexadecimal CString number devAddress = "A00761ADEFA6" (obtained from the address of the device by removing ":" between digits).

What is the easiest way to convert it to a numeric value? Preferably using the standard function.

    2 answers 2

    int n; sscanf(devAddress, "%x", &n); 

    Make sure not to overflow!

    For 64-bit addresses:

     long long n; sscanf(devAddress, "%llx", &n); 
    • the int value is clearly not enough to store the address value, the maximum value will be FF: FF: FF: FF: FF: FF = 2 ^ 48-1 if I was not mistaken - Eugene
    • @ Eugen hmm ... do we, like, have the digit capacity of int, which is the same as the processor, and, therefore, with the address width? Well, if there are any such features, hmm ... well, you can correct the answer ... - kirelagin
    • And in the example, and true, 12 digits - therefore, 6 bytes ... funny. - kirelagin

    strtol - there is a whole family of functions. various numeric bases. basic function for your needs. essentially atoi is a wrapper over it.

    http://opennet.ru/man.shtml?topic=strtol&category=3&russian=0