I'm looking for a way to convert a hexadecimal string to a ULONG variable.

For general Flowcode discussion that does not belong in the other sections.
Post Reply
seokgi
Posts: 219
http://meble-kuchenne.info.pl
Joined: Thu Dec 03, 2020 1:43 pm
Has thanked: 8 times
Been thanked: 8 times

Flowcode v10 I'm looking for a way to convert a hexadecimal string to a ULONG variable.

Post 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.

medelec35
Matrix Staff
Posts: 2129
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 659 times
Been thanked: 717 times

Re: I'm looking for a way to convert a hexadecimal string to a ULONG variable.

Post 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.
Attachments
Hex String to Ulong.fcfx
(14.08 KiB) Downloaded 11 times
Martin

mnfisher
Valued Contributor
Posts: 1686
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 146 times
Been thanked: 785 times

Re: I'm looking for a way to convert a hexadecimal string to a ULONG variable.

Post 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 🙄

seokgi
Posts: 219
Joined: Thu Dec 03, 2020 1:43 pm
Has thanked: 8 times
Been thanked: 8 times

Re: I'm looking for a way to convert a hexadecimal string to a ULONG variable.

Post by seokgi »

Thanks to your interest and help, I'm doing well. I'm sending you my macro file for reference.
Attachments
DS18B20_Temp_Serial.fcm
(14.34 KiB) Downloaded 5 times

mnfisher
Valued Contributor
Posts: 1686
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 146 times
Been thanked: 785 times

Re: I'm looking for a way to convert a hexadecimal string to a ULONG variable.

Post 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

Post Reply