You are not logged in.

Dear visitor, welcome to Jabaco - Community. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

OlimilO

Intermediate

  • "OlimilO" is male
  • "OlimilO" started this thread

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

1

Wednesday, September 30th 2009, 10:03am

assigning hex constants

Hi, is there something what i do not see, or is it in fact a bug?

Jabaco Source

1
2
3
4
5
6
7
8
Dim v As Integer
   v = &H8000
   MsgBox Hex(v) & " " & CStr(v)
'the Jabaco Integer is a int32
'what we expect: 
   '8000 32768
'what we get:
   'FFFF8000 -32768


The problem is that there is no possibility to distinguish between int16 and in32 hex values.

In VB there is the "&"-sign for Longs.



OlimilO

A1880

Intermediate

  • "A1880" is male

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

2

Wednesday, September 30th 2009, 11:45am

seems to be a bug.
Jabaco definitely generate an assignment to -32768 as JVM bytecode
The most significant bit is taken as sign here. It does not help to write &H08000 to suppress this sign extension.

A1880

OlimilO

Intermediate

  • "OlimilO" is male
  • "OlimilO" started this thread

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

3

Wednesday, September 30th 2009, 1:51pm

workaround

thanks, little workaround:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Public Sub Form_Load()
   
   Dim i As Integer
   
   i = &HABCD
   MsgBox Hex(i) & " " & CStr(i)
   
   i = CopyBytes(&HABCD)   
   MsgBox Hex(i) & " " & CStr(i)
   
End Sub
Function CopyBytes(s As java#lang#Short) As Integer
   If s < 0 Then
      CopyBytes = s XOr &HFFFF0000
   Else
      CopyBytes = s
   End If
End Function

OlimilO

A1880

Intermediate

  • "A1880" is male

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

4

Wednesday, September 30th 2009, 4:11pm

Here comes another workaround for longer hex strings:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Public Sub Form_Load()
   Dim i As Integer 
   
   test "ABC"
   test "ABCD"
   test "FFFF"
   test "0"
   test "ABCDEF"
   test "00G00"
End Sub

Private Sub test(s As String)
   Dim i As Integer 
   
   i = Hex2Dec(s)
   Debug.Print Hex(i) & " " & i
End Sub

Public Function Hex2Dec(s As String)
   Dim pos As Integer 
   Dim p As Integer 
   Dim v As Integer 
   
   For pos = 1 To Len(s)
      v = InStr("0123456789abcdef", LCase(Mid(s, pos, 1)))
      If v < 1 Then Goto ErrHandler
      
      p = (16 * p) + v - 1
   Next pos
   
   Hex2Dec = p
   Exit Function
   
ErrHandler:
   Debug.print "Hex2Dec: Invalid Hex string '" & s & "'"
End Function


Greetings

A1880

OlimilO

Intermediate

  • "OlimilO" is male
  • "OlimilO" started this thread

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

5

Friday, October 2nd 2009, 10:43am

Hi,
Yes, cool code, and it's cool that basic code completely runs on Jabaco. Have you mentioned the function java#lang#Long.valueOf

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Public Sub Form_Load()
   
   Dim i As Integer
   Dim l As Long
   Dim hs As String
   
   hs = "ABCDEF12"
   MsgBox Len(hs)
   
   i = Hex2Int(hs)
   MsgBox Hex(i)
   
   hs = hs & "2345678" '9"
   MsgBox Len(hs)
   
   l = Hex2Lng(hs)
   MsgBox Hex(l)
   
End Sub
Function Hex2Int(H As java#lang#String) As Integer
   If H.startsWith("&H") Or H.startsWith("0x") Then H = H.substring(2)
   Hex2Int = java#lang#Long.valueOf(H, 16)
End Function
Function Hex2Lng(H As java#lang#String) As Long
   If H.startsWith("&H") Or H.startsWith("0x") Then H = H.substring(2)
   'Argh but is does not properly handle the unsigned case
   Hex2Lng = java#lang#Long.valueOf(H, 16)
End Function


have you any idea how to handle correctly the unsigned case of the Long-datatype?

OlimilO

theuserbl

Intermediate

Posts: 436

Date of registration: Dec 20th 2008

  • Send private message

6

Thursday, May 15th 2014, 12:46pm

Added the Hex-Support algorithm of A1880 in the newest Jabaco Framework:
[ http://www.jabaco.org/wiki/Latest_JabacoFramework_Binary ]
For information of the changes, look at the linked page.

Now this is possible:

Jabaco Source

1
2
3
4
5
6
7
8
Public Sub Form_Load()
   RichTextBox1.Text = ""
   RichTextBox1.Print CLng("142")
   RichTextBox1.Print CLng("&H1ad2")
   RichTextBox1.Print CLng("&O142")
   RichTextBox1.Print CLng("&B101")
   RichTextBox1.Print Bin("148")
End Sub


Greatings
theuserbl

This post has been edited 1 times, last edit by "theuserbl" (May 15th 2014, 12:52pm)


Rate this thread
WoltLab Burning Board