2

I want to convert a long hex string to a number value. I will use the number value in a for loop.

Any ideas?

There have been some great [posts][1] on how to achieve this for small Hex strings natively in Swift (or using Foundation library). But I could not find a post that dealt with 32 character Hex fields.

Take for example:

4D275F68-B95B-42C1-822D-15E561163FFF

How can I change that to a number?

Edit - The following articles didn't answer this question.

http://stackoverflow.com/questions/24229505/how-to-convert-an-int-to-hex-string-in-swift http://stackoverflow.com/questions/37821112/convert-hex-to-decimal-in-swift http://stackoverflow.com/questions/26284223/how-to-convert-hex-number-to-bin-in-swift

rustyMagnet
  • 3,479
  • 1
  • 31
  • 41
  • How large? Does the result fit into a 64-bit integer? If not, how would you want to represent it? – Martin R Dec 30 '15 at 14:27
  • @MartinR, thanks for the reply. I added an example so you can see how large. I don't know what data type I am really talking about here as I suspect a 32 char hex number converts into a long long int. I am trying to emulate this: http://guid-convert.appspot.com/ – rustyMagnet Oct 23 '16 at 14:03
  • Your 32-digit hexadecimal example represents a UUID, it's basically a 128-bit binary data. I cannot find any use cases for its decimal representation. What do you really want to do after you _change that to a number?_ – OOPer Oct 23 '16 at 14:27
  • @OOPer thanks for the comment. I want to use the number to set the upper limit for a loop. I want to see whether I can loop through from the lower to upper limit. This is in the realm of "not enough computing power" but I suspect a fault in the randomness of the Database generated GUID. This person seems to have achieved it: http://guid-convert.appspot.com/ – rustyMagnet Oct 24 '16 at 08:51
  • Thanks for your comment, but I don't think it's a practical use case, and I'm afraid I cannot be any help of you. – OOPer Oct 24 '16 at 13:44

0 Answers0