B4R Question How can I convert an byte array to one float number ?

vali khandangoll

Active Member
Hi all of you.
I have an byte array and I want convert it to a float number value.
because I want plus that with another number.

my help me ?
 

vali khandangoll

Active Member
You can use ByteConverter from rRandomAccessFile to convert bytes to floats.
I am sorry
I can't undrestand

for example on below code
Dim bc As ByteConverter
Dim L() As Byte
Serial1.Initialize(9600)
Log("AppStart")

L=bc.SubString2("1234567890",5,8)
Log(L)

L is 678
please save L*100 on a variable and then print that
thanks again
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Please use [code]code here...[/code] tags when posting code.

Ignore my previous answer, it was for a different scenario.

When you have a text representation of a number stored in an array of bytes, you need to first convert it to a string:
B4X:
Dim L() As Byte = bc.SubString2("1234567890",5,8)
Dim n As Int = bc.StringFromBytes(L)
Log(n * 100)
 
Upvote 0

vali khandangoll

Active Member
Please use [code]code here...[/code] tags when posting code.

Ignore my previous answer, it was for a different scenario.

When you have a text representation of a number stored in an array of bytes, you need to first convert it to a string:
B4X:
Dim L() As Byte = bc.SubString2("1234567890",5,8)
Dim n As Int = bc.StringFromBytes(L)
Log(n * 100)
Hi again
in my question n*100 must be equal to 67800
but in your code return 2264
code picture attached
 

Attachments

  • Untitled.jpg
    Untitled.jpg
    254.3 KB · Views: 175
Upvote 0

janderkan

Well-Known Member
Licensed User
Longtime User
You cannot hold value 67.800 in an INT, not even in a UINT
Max value of an INT is 32.767
Max value of a UINT is 65.535
Max value of a LONG is 2.147.483.647
B4X:
Dim L() As Byte = bc.SubString2("1234567890",5,8)
Dim n As Long = bc.StringFromBytes(L)
Log(n * 100)
 
Upvote 0

vali khandangoll

Active Member
You cannot hold value 67.800 in an INT, not even in a UINT
Max value of an INT is 32.767
Max value of a UINT is 65.535
Max value of a LONG is 2.147.483.647
B4X:
Dim L() As Byte = bc.SubString2("1234567890",5,8)
Dim n As Long = bc.StringFromBytes(L)
Log(n * 100)
ok.
undrestand.

thanks .
 
Upvote 0
Top