Cableguy Expert Licensed User Longtime User Nov 16, 2016 #1 Hi Guys I am trying to get a byte converted into an integer... My byte array is formated as follows: 0X71+4 byte binary data+0xff 0xff 0xff So I need to convert those 4Bytes into an Integer, But HOW????? (The bytes are in litle endian order) Please help [EDIT] since I cannot delete the post, I leave my working solution here: Bit.ParseInt(bytec.HexFromBytes(bytec.SubString2(Buffer,9,13)),16) bytec is a byteconverter object Last edited: Nov 16, 2016
Hi Guys I am trying to get a byte converted into an integer... My byte array is formated as follows: 0X71+4 byte binary data+0xff 0xff 0xff So I need to convert those 4Bytes into an Integer, But HOW????? (The bytes are in litle endian order) Please help [EDIT] since I cannot delete the post, I leave my working solution here: Bit.ParseInt(bytec.HexFromBytes(bytec.SubString2(Buffer,9,13)),16) bytec is a byteconverter object
Erel B4X founder Staff member Licensed User Longtime User Nov 17, 2016 #2 Integers in B4R are two bytes. Your solution wastes a lot of memory. You can use RandomAccessFile to read integers or longs from the array. If you can, use B4RSerializator to send the data. It will be simpler and more efficient. Upvote 0
Integers in B4R are two bytes. Your solution wastes a lot of memory. You can use RandomAccessFile to read integers or longs from the array. If you can, use B4RSerializator to send the data. It will be simpler and more efficient.
Cableguy Expert Licensed User Longtime User Nov 17, 2016 #3 In this case I am receiving this data... How can I then convert it without wasting memory? (In this particular case I only need to convert the first byte as my value as a max of int=100) Upvote 0
In this case I am receiving this data... How can I then convert it without wasting memory? (In this particular case I only need to convert the first byte as my value as a max of int=100)
Erel B4X founder Staff member Licensed User Longtime User Nov 17, 2016 #4 B4X: Dim raf As RandomAccessFile raf.Initialize(Buffer, True) Dim i As Int = raf.ReadLong32 (9) Upvote 0
Cableguy Expert Licensed User Longtime User Nov 17, 2016 #5 Many thanks, will try later This is for my GUI using a Nextion, what a great display! Upvote 0