giggetto71 Active Member Licensed User Longtime User Jan 23, 2021 #1 Hi, I have used the below function by Erel for some time in B4J from another case: B4X: Copy Sub StringToUnsignedInt (Str As String) As Long Dim converter As ByteConverter Dim a(8) As Byte Dim i() As Byte = converter.HexToBytes(Str) Bit.ArrayCopy(i, 0, a, 4, 4) Dim ll() As Long = converter.LongsFromBytes(a) Return ll(0) End Sub B4r bit object does not have the "ArrayCopy" method so it won't build. Any workaround? thanks!
Hi, I have used the below function by Erel for some time in B4J from another case: B4X: Copy Sub StringToUnsignedInt (Str As String) As Long Dim converter As ByteConverter Dim a(8) As Byte Dim i() As Byte = converter.HexToBytes(Str) Bit.ArrayCopy(i, 0, a, 4, 4) Dim ll() As Long = converter.LongsFromBytes(a) Return ll(0) End Sub B4r bit object does not have the "ArrayCopy" method so it won't build. Any workaround? thanks!
Erel B4X founder Staff member Licensed User Longtime User Jan 24, 2021 #2 What is the expected input and output? Upvote 0
giggetto71 Active Member Licensed User Longtime User Jan 24, 2021 #3 The input is a string like "0x1562AFD" and the output should be its long equivalent. Maybe there is an easier way..sorry if it's a stupid request. Upvote 0
The input is a string like "0x1562AFD" and the output should be its long equivalent. Maybe there is an easier way..sorry if it's a stupid request.
thetahsk Active Member Licensed User Longtime User Jan 24, 2021 #4 giggetto71 said: The input is a string like "0x1562AFD" and the output should be its long equivalent. Maybe there is an easier way..sorry if it's a stupid request. Click to expand... B4X: Copy Dim v_ulong As ULong = Bit.ParseInt("1562AFD", 16) Upvote 0
giggetto71 said: The input is a string like "0x1562AFD" and the output should be its long equivalent. Maybe there is an easier way..sorry if it's a stupid request. Click to expand... B4X: Copy Dim v_ulong As ULong = Bit.ParseInt("1562AFD", 16)
giggetto71 Active Member Licensed User Longtime User Jan 24, 2021 #6 still have some issues. for some numbers the method throws NumberFormatException. For example Dim v_ulong As ULong = Bit.ParseInt("E0E09E61", 16) any idea? java.lang.NumberFormatException: For input string: "E0E09E61" at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.base/java.lang.Integer.parseInt(Integer.java:652) at anywheresoftware.b4a.keywords.Bit.ParseInt(Bit.java:86) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632) at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234) at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ................... Upvote 0
still have some issues. for some numbers the method throws NumberFormatException. For example Dim v_ulong As ULong = Bit.ParseInt("E0E09E61", 16) any idea? java.lang.NumberFormatException: For input string: "E0E09E61" at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.base/java.lang.Integer.parseInt(Integer.java:652) at anywheresoftware.b4a.keywords.Bit.ParseInt(Bit.java:86) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632) at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234) at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ...................
Erel B4X founder Staff member Licensed User Longtime User Jan 24, 2021 #7 Code: Copy Dim bc As ByteConverter Dim b() As Byte = bc.HexToBytes("E0E09E61") Dim l() As ULong = bc.ULongsFromBytes(b) Log(l(0)) giggetto71 said: The input is a string like "0x1562AFD" and the output should be its long equivalent. Click to expand... Not good enough. You should post the expected number. There are several possible outputs. Upvote 0
Code: Copy Dim bc As ByteConverter Dim b() As Byte = bc.HexToBytes("E0E09E61") Dim l() As ULong = bc.ULongsFromBytes(b) Log(l(0)) giggetto71 said: The input is a string like "0x1562AFD" and the output should be its long equivalent. Click to expand... Not good enough. You should post the expected number. There are several possible outputs.
giggetto71 Active Member Licensed User Longtime User Jan 24, 2021 #8 Not good enough. You should post the expected number. There are several possible outputs. Click to expand... ok. I would like for example to input FF02FD and get 16712445 which is the decimal conversion of that Hex number. Upvote 0
Not good enough. You should post the expected number. There are several possible outputs. Click to expand... ok. I would like for example to input FF02FD and get 16712445 which is the decimal conversion of that Hex number.
giggetto71 Active Member Licensed User Longtime User Jan 24, 2021 #9 actually I get the right result with @thetahsk solution. sorry .. Upvote 0
thetahsk Active Member Licensed User Longtime User Jan 24, 2021 #10 giggetto71 said: still have some issues. for some numbers the method throws NumberFormatException. For example Dim v_ulong As ULong = Bit.ParseInt("E0E09E61", 16) any idea? java.lang.NumberFormatException: For input string: "E0E09E61" at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.base/java.lang.Integer.parseInt(Integer.java:652) at anywheresoftware.b4a.keywords.Bit.ParseInt(Bit.java:86) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632) at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234) at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ................... Click to expand... This exception comes from B4J. With B4R you get the right results Upvote 0
giggetto71 said: still have some issues. for some numbers the method throws NumberFormatException. For example Dim v_ulong As ULong = Bit.ParseInt("E0E09E61", 16) any idea? java.lang.NumberFormatException: For input string: "E0E09E61" at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.base/java.lang.Integer.parseInt(Integer.java:652) at anywheresoftware.b4a.keywords.Bit.ParseInt(Bit.java:86) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632) at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234) at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ................... Click to expand... This exception comes from B4J. With B4R you get the right results
giggetto71 Active Member Licensed User Longtime User Jan 25, 2021 #11 This exception comes from B4J. With B4R you get the right results Click to expand... true. I was not at home and did not have any ESP8266 to try to I made a quick test with B4J assuming a similar behavior.. Upvote 0
This exception comes from B4J. With B4R you get the right results Click to expand... true. I was not at home and did not have any ESP8266 to try to I made a quick test with B4J assuming a similar behavior..