P Paladium Member Licensed User Longtime User Feb 16, 2011 #1 Hi there, I got another question. I need to convert hex values into decimal values. In .net I use val and "&H" plus the hex value. That's all. How do I manage this in B4A? Please help. Thanks a lot. Markus
Hi there, I got another question. I need to convert hex values into decimal values. In .net I use val and "&H" plus the hex value. That's all. How do I manage this in B4A? Please help. Thanks a lot. Markus
Erel B4X founder Staff member Licensed User Longtime User Feb 16, 2011 #2 In Basic4android you should write 0x. Code: Dim i As Int i = 0xABC3456 Upvote 0
P Paladium Member Licensed User Longtime User Feb 16, 2011 #3 Thanks for the quick reply. Tried it but get a "numberformatexception". Small example: PHP: Sub ed3_TextChanged (Old As String, New As String) Dim aaa As Int aaa = "0xab12" Msgbox(aaa,"") End Sub Upvote 0
Thanks for the quick reply. Tried it but get a "numberformatexception". Small example: PHP: Sub ed3_TextChanged (Old As String, New As String) Dim aaa As Int aaa = "0xab12" Msgbox(aaa,"") End Sub
P Paladium Member Licensed User Longtime User Feb 16, 2011 #4 Same when using edit text: PHP: Sub ed3_TextChanged (Old As String, New As String) Dim aaa As Int aaa = 0x & ed3.Text Msgbox(aaa,"") End Sub PHP: Compiling generated Java code. Error B4A line: 69 aaa = 0x & ed3.Text javac 1.6.0_23 src\com\asdbsfdbsdfb\binary.java:259: hexadecimal numbers must contain at least one hexadecimal digit _aaa = (int)(Double.parseDouble(BA.NumberToString(0x)+mostCurrent._ed3.getText())); ^ 1 error Upvote 0
Same when using edit text: PHP: Sub ed3_TextChanged (Old As String, New As String) Dim aaa As Int aaa = 0x & ed3.Text Msgbox(aaa,"") End Sub PHP: Compiling generated Java code. Error B4A line: 69 aaa = 0x & ed3.Text javac 1.6.0_23 src\com\asdbsfdbsdfb\binary.java:259: hexadecimal numbers must contain at least one hexadecimal digit _aaa = (int)(Double.parseDouble(BA.NumberToString(0x)+mostCurrent._ed3.getText())); ^ 1 error
Erel B4X founder Staff member Licensed User Longtime User Feb 16, 2011 #5 If you want to parse a hex string then you should use: Code: Dim i As Int i = Bit.ParseInt("ABC123", 16) Upvote 0
If you want to parse a hex string then you should use: Code: Dim i As Int i = Bit.ParseInt("ABC123", 16)
R RichardBernard Member Licensed User Longtime User Jul 24, 2013 #6 If the data type Int has the range : 4bytes signed: -2147483648 to 2147483647 Then why can't I get this code to run: Code: Dim s As String Dim i As Int s = "80000002" ' 0h80000002 = -2,147,483,646 i = Bit.ParseInt(s,16) Comp_Gain_Offset.Text = i I get the error: Code: main_fillspilabels (B4A line: 1328) i = Bit.ParseInt(s,16) java.lang.NumberFormatException: Invalid int: "80000002" at java.lang.Integer.invalidInt(Integer.java:138) at java.lang.Integer.parse(Integer.java:382) at java.lang.Integer.parseInt(Integer.java:366) at anywheresoftware.b4a.keywords.Bit.ParseInt(Bit.java:80) at ce3.arsham.SmartScale.main._fillspilabels(main.java:2163) at ce3.arsham.SmartScale.main._spireceive_click(main.java:3296) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169) at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:834) at anywheresoftware.b4a.keywords.Common.CallSubNew(Common.java:785) at ce3.arsham.SmartScale.main._cbd_tmr_tick(main.java:1813) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169) at anywheresoftware.b4a.objects.Timer$TickTack.run(Timer.java:105) at android.os.Handler.handleCallback(Handler.java:725) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5039) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) at dalvik.system.NativeStart.main(Native Method) Click to expand... I would appreciate your help, Richard Upvote 0
If the data type Int has the range : 4bytes signed: -2147483648 to 2147483647 Then why can't I get this code to run: Code: Dim s As String Dim i As Int s = "80000002" ' 0h80000002 = -2,147,483,646 i = Bit.ParseInt(s,16) Comp_Gain_Offset.Text = i I get the error: Code: main_fillspilabels (B4A line: 1328) i = Bit.ParseInt(s,16) java.lang.NumberFormatException: Invalid int: "80000002" at java.lang.Integer.invalidInt(Integer.java:138) at java.lang.Integer.parse(Integer.java:382) at java.lang.Integer.parseInt(Integer.java:366) at anywheresoftware.b4a.keywords.Bit.ParseInt(Bit.java:80) at ce3.arsham.SmartScale.main._fillspilabels(main.java:2163) at ce3.arsham.SmartScale.main._spireceive_click(main.java:3296) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169) at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:834) at anywheresoftware.b4a.keywords.Common.CallSubNew(Common.java:785) at ce3.arsham.SmartScale.main._cbd_tmr_tick(main.java:1813) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169) at anywheresoftware.b4a.objects.Timer$TickTack.run(Timer.java:105) at android.os.Handler.handleCallback(Handler.java:725) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5039) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) at dalvik.system.NativeStart.main(Native Method) Click to expand... I would appreciate your help, Richard
NJDude Expert Licensed User Longtime User Jul 24, 2013 #7 This works: Code: ... s = "7FFFFFFE" ... Upvote 0
R RichardBernard Member Licensed User Longtime User Jul 24, 2013 #8 NJDude said: This works: Code: ... s = "7FFFFFFE" ... Click to expand... But I wanted negative numbers... I got it working using this tho: Code: b = Conv.HexToBytes(s) For j = 0 To 3 int = int * 256 + Bit.AND(b(j), 255) Next Pressure.Text = i Upvote 0
NJDude said: This works: Code: ... s = "7FFFFFFE" ... Click to expand... But I wanted negative numbers... I got it working using this tho: Code: b = Conv.HexToBytes(s) For j = 0 To 3 int = int * 256 + Bit.AND(b(j), 255) Next Pressure.Text = i