B4R Question DoublesFromByte quesiton

daveinhull

Active Member
Licensed User
Longtime User
Hi (and sorry for the simple questions)

I get a "Cannot cast type: {Type=Double,Rank=1, RemoteObject=True} to: {Type=Double,Rank=0, RemoteObject=True}" on the dHeight = line, but can't see what I'm doing wrong, any help appreciated.

B4X:
    Dim Height(5) as Byte
...   
...   
...
    Dim BC As ByteConverter
    Dim dHeight As Double
    dHeight = BC.DoublesFromBytes(Height)

Dave
 
B4X:
Dim Height(5) as Byte
...   
...   
...
    Dim BC As ByteConverter
    Dim dHeights() As Double
    dHeights = BC.DoublesFromBytes(Height)
    Dim dHeight As Double = dHeights(0)
 
Upvote 0
Hi,

Many thanks for the reply and it now compiles, but I'm not getting the right result.
Ok, so maybe I've misunderstood what DoublesFromBytes means.
I have a byte array with 5 bytes containing ASCI characters that represent a floating point number, say 34.1 (so 51,50,46,49,00) and I was assuming that it would convert this to a 4 byte numeric value representing the double value, but I get 0.0000 if I log it

Thanks
Dave
 
Upvote 0
Perfect! Many thanks, although I must admit I'm totally confused with all the conversions that are going on - I guess I'll get their.
 
Upvote 0
Hi, yes I know that which is why I was thinking the function DoublesFromBytes would do the conversion. Apparently its StringFromBytes which must create a string representation of the double and then somehow assigning a string of a double to a double variable does the conversion. I get this with a constant but not with an variable. In other languages doing something like:
A ="12.3"
B = A
Where A is a string and B is a double wouldnt work.
 
Upvote 0
A useful relevant function:

1594157947208.png
 
Last edited:
Upvote 0
Anyway, please note your example: 34.1 (51,50,46,49,00) is actually 32.1 with a trailing nul char that can safely be omitted
 
Upvote 0
Back
Top