Page 1 of 1
I'm looking for a way to convert a hexadecimal string to a ULONG variable.
Posted: Wed Oct 15, 2025 9:18 am
by seokgi
Hello.
When I read the serial number of a DS18B20, it outputs a 12-digit string.
I'd like to convert this to a ULONG variable.
Is there a quick and easy way to do this?
Thank you.
Re: I'm looking for a way to convert a hexadecimal string to a ULONG variable.
Posted: Wed Oct 15, 2025 12:32 pm
by medelec35
Hello.
It's not that straight forward as 12 digits = 48 bits and not the ULong 32bits.
For that reason you will require two x 32bits ULongs (Or Martins suggestion below of 3 x 16bits)
I have created a flowchart that will convert the 48bits to ULongL and ULongH
If you want a singe ULong value then you could either use just ULongL .
Alternatively, you could use ULongL and OR it with ULongH to give a new ULongL just in case the ULongL of one device is the same as another but ULongH is different.
The likelihood of that happening is veling low indeed.
Re: I'm looking for a way to convert a hexadecimal string to a ULONG variable.
Posted: Wed Oct 15, 2025 12:32 pm
by mnfisher
12 digits won't fit in a 32 bit variable - which could hold 8 hex digits (4bits per digit)
You could convert to 3 x 16bit (unsigned int)
Martin
Ben beat me to it

Re: I'm looking for a way to convert a hexadecimal string to a ULONG variable.
Posted: Thu Oct 16, 2025 12:49 pm
by seokgi
Thanks to your interest and help, I'm doing well. I'm sending you my macro file for reference.
Re: I'm looking for a way to convert a hexadecimal string to a ULONG variable.
Posted: Thu Oct 16, 2025 2:26 pm
by mnfisher
As an alternative method -take a look at 'hash functions/values' - this is a common technique to assign a (not necessarily but usually) unique value to a string.
See
https://en.wikipedia.org/wiki/Hash_function
For some interesting ideas
Martin