J jo1234 Active Member Licensed User Longtime User Dec 15, 2014 #1 Hi I would like to convert a String ("1011") to an Int and finally to a Hex ("B"). In B4A I use Code: Dim sHexPattern As String sHexPattern = Bit.ToHexString(Bit.ParseInt("1011")) What would be the code in B4i? Thanks a lot!
Hi I would like to convert a String ("1011") to an Int and finally to a Hex ("B"). In B4A I use Code: Dim sHexPattern As String sHexPattern = Bit.ToHexString(Bit.ParseInt("1011")) What would be the code in B4i? Thanks a lot!
Erel B4X founder Staff member Licensed User Longtime User Dec 15, 2014 #2 You can use this code (in B4A as well): Code: Dim bc As ByteConverter Log(bc.HexFromBytes(Array As Byte(Bit.ParseInt("1011", 2)))) 'will print 0B. bc.HexFromBytes is in most cases better than Bit.ToHexString (which is not available in B4i) as it writes each byte as two characters adding 0 if needed. You can add .SubString(1) if you want to get B instead of 0B. Upvote 0
You can use this code (in B4A as well): Code: Dim bc As ByteConverter Log(bc.HexFromBytes(Array As Byte(Bit.ParseInt("1011", 2)))) 'will print 0B. bc.HexFromBytes is in most cases better than Bit.ToHexString (which is not available in B4i) as it writes each byte as two characters adding 0 if needed. You can add .SubString(1) if you want to get B instead of 0B.
mrossen Active Member Licensed User Longtime User May 13, 2018 #3 Hi, Code: Dim bc As ByteConverter Log(bc.HexFromBytes(Array As Byte("140")))) 'will print 8C. Code: Dim bc As ByteConverter Log(bc.HexFromBytes(Array As Byte("7440")))) 'will print 10. The last example should return 1d10. The problem is that the number can not be higher than 255 for the byte. How do I convert number higher than 255? Mogens Upvote 0
Hi, Code: Dim bc As ByteConverter Log(bc.HexFromBytes(Array As Byte("140")))) 'will print 8C. Code: Dim bc As ByteConverter Log(bc.HexFromBytes(Array As Byte("7440")))) 'will print 10. The last example should return 1d10. The problem is that the number can not be higher than 255 for the byte. How do I convert number higher than 255? Mogens
mrossen Active Member Licensed User Longtime User May 13, 2018 #4 Hi again, Now I got it to work, but is this the right way to do it? Code: Log(bc.HexFromBytes(bc.IntsToBytes(Array As Int("7440")))) 'will print 00001d10 Mogens Upvote 0
Hi again, Now I got it to work, but is this the right way to do it? Code: Log(bc.HexFromBytes(bc.IntsToBytes(Array As Int("7440")))) 'will print 00001d10 Mogens
Erel B4X founder Staff member Licensed User Longtime User May 13, 2018 #5 I'm sorry but you should never post in a thread from 2014. Always start a new thread for your question. Upvote 0
I'm sorry but you should never post in a thread from 2014. Always start a new thread for your question.