# B4R Code Snippethex to int

found, that sometimes it's easyer, to knit it up...

private Sub intFromHex(b1() As Byte)As Int
Dim in As Int
'send( JoinStrings(Array As String("b1 :", bc.StringFromBytes(b1))) ) 'test

For i = 0 To b1.Length - 1
Dim m As Double = Power(16,b1.Length-1-i) ' multiplikator
If b1(i)>60 Then
b1(i) = b1(i) - 55
in = in + b1(i)*m
Else
b1(i) = b1(i) - 48
in = in + b1(i)*m
End If
'send( JoinStrings(Array As String(" i: ", i," m: ", m)) ) 'test
Next

'send( JoinStrings(Array As String("in :", in)) ) 'test
Return in
End Sub

... but be carefull, b1 is to be destructed...

Last edited:

#### Erel

##### B4X founder
Staff member
Licensed User
Longtime User
Another option:
B4X:
``Dim i As Int = Bit.ParseInt(bc.StringFromBytes(b1), 16)``

#### Hans- Joachim Krahe

##### Active Member
Licensed User
Longtime User
... thank you, thats much easyer

#### rgarnett1955

##### Active Member
Licensed User
Longtime User
For 32 bit integers you need to use:

Convert Hexadecimal string 32 Bit to integer:
``Dim i As Int = Bit.ParseLong(bc.StringFromBytes(b1), 32)``

I know its an old post, but it is still a useful one.

### Similar Threads

Replies
10
Views
557
B4R Question INT to HEX
Replies
2
Views
923
B4R Question string hex to decimal
Replies
1
Views
1K
Replies
1
Views
2K
Replies
8
Views
3K