D daveinhull Active Member Licensed User Longtime User Jul 7, 2020 #1 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
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
janderkan Well-Known Member Licensed User Longtime User Jul 7, 2020 #2 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
B4X: Dim Height(5) as Byte ... ... ... Dim BC As ByteConverter Dim dHeights() As Double dHeights = BC.DoublesFromBytes(Height) Dim dHeight As Double = dHeights(0)
E emexes Expert Licensed User Longtime User Jul 7, 2020 #3 daveinhull said: B4X: Dim Height(5) as Byte Click to expand... Are Doubles 5 bytes in B4R? Applesoft Basic déjà vu. Upvote 0
daveinhull said: B4X: Dim Height(5) as Byte Click to expand... Are Doubles 5 bytes in B4R? Applesoft Basic déjà vu.
janderkan Well-Known Member Licensed User Longtime User Jul 7, 2020 #4 No it is 4 bytes, you can see it here https://www.b4x.com/android/forum/threads/data-types.65666/#content Upvote 0
No it is 4 bytes, you can see it here https://www.b4x.com/android/forum/threads/data-types.65666/#content
D daveinhull Active Member Licensed User Longtime User Jul 7, 2020 #5 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
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
janderkan Well-Known Member Licensed User Longtime User Jul 7, 2020 #6 B4X: Dim bytes() As Byte = Array As Byte(51,50,46,49,00) Dim Height As Double = bc.StringFromBytes(bytes) Log(Height) Upvote 0
B4X: Dim bytes() As Byte = Array As Byte(51,50,46,49,00) Dim Height As Double = bc.StringFromBytes(bytes) Log(Height)
D daveinhull Active Member Licensed User Longtime User Jul 7, 2020 #7 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
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.
NoNickName Member Licensed User Jul 7, 2020 #9 A double is something different than a string literal. Upvote 0
D daveinhull Active Member Licensed User Longtime User Jul 7, 2020 #10 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
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.
E emexes Expert Licensed User Longtime User Jul 7, 2020 #11 A useful relevant function: Last edited: Jul 8, 2020 Upvote 0
NoNickName Member Licensed User Jul 8, 2020 #12 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
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