Hex to decimal conversion

Paladium

Member
Licensed User
Longtime User
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
 

Paladium

Member
Licensed User
Longtime User
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

Paladium

Member
Licensed User
Longtime User
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

RichardBernard

Member
Licensed User
Longtime User
If the data type Int has the range : 4bytes signed: -2147483648 to 2147483647
Then why can't I get this code to run:
B4X:
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:
B4X:
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)

I would appreciate your help,
Richard
 
Upvote 0
Top