B4A Library ByteConverter library

It's occasionally useful to be able to poke around in things as arrays of bytes so this library lets you do it.

It can transform arrays of primitive types to and from arrays of bytes with the "endian-ness" of the conversion specified. If you need endian-ness you will either know about it or rather quickly find out. :)

Byte arrays can be transformed to and from a hexadecimal string representation.

Strings can be transformed to and from arrays of Bytes using specified encodings and to and from arrays of Chars.

An array copy method is thrown in for good measure.

EDIT :- Version 1.1 posted. See post #4 for details.

Download link: www.b4x.com/android/files/ByteConverter1.1.zip
 
Last edited by a moderator:

Pauloc

New Member
Licensed User
Longtime User
Good evening
I downloaded byteconverter several times
WinZip cannot unzip it , says it is corrupted ?
Could you verify and inform me :
mail : " pauloc@aliceadsl.fr "

Merci d'avance
Best regards
 

Pauloc

New Member
Licensed User
Longtime User
re

I downloaded it right now and unziped it with 7Zip without any problem.

Best regards.

I can't understand
I tried with winzip12 , winrar , 7zip , on 2 computers Win7
and i can't unzip it ????
I never had any problem like that , and just now i unzipped a few files to try
without problem ???
Any idea or possibility to post unzipped file
Thanks
 

Rafal Galewski

Member
Licensed User
Longtime User
Byte Array To Decimal and Decimal to string

Hi,

How to use Your converter convert:

Byte Array to Decimal

And then

Decimal to String ?

Please send to me how to do it.

Thnk You in Advance.
 

raphaelcno

Active Member
Licensed User
Longtime User
If you want to convert hexadecimal number stored as a string to a decimal number you can use following code:
B4X:
Dim Str_HexNumber As String
Str_HexNumber = "FF"
Dim Int_Number As Int
Int_Number = Bit.ParseInt(Str_HexNumber, 16)  ' => Int_Number = 255
 
Last edited:

Rafal Galewski

Member
Licensed User
Longtime User
If you want to convert hexadecimal number stored as a string to a decimal number you can use following code:
B4X:
Dim Str_HexNumber As String
Str_HexNumber = "FF"
Dim Int_Number
Int_Number = Bit.ParseInt(Str_HexNumber, 16)  ' => Int_Number = 255

And how change decimal or Hex to string ?

Thank You
 

kiki78

Active Member
Licensed User
Longtime User
Partial conversion

Dear agraham,

First, many thank's for this usefull library. :)

May you add, in future release, partial conversion of array ?
For now we can do that with ArrayCopy before.
But it's simpler if we can have, for example, "Sub2" with Offset and Count parameters.

Best Regards
 

TK Tang

New Member
Licensed User
Longtime User
Hi,

I am a new b4a user.

I just downloaded ByteConverter library file and noticed it is in dll file format which I do not know how to have it recognised by B4A software. I noticed all other library files format is in xml and jar but this one is different.

What should I do to get this library recognised in B4A?

Thanks !
 

TK Tang

New Member
Licensed User
Longtime User
Hi Andrew,

Actually, I downloaded the attached file from the first post as that is the only one I can find in this forum.

Appreciate if you can re-send the xml/jar format files please.

Thanks..TK Tang
 

kiki78

Active Member
Licensed User
Longtime User
Hi agraham,

Another time many thanks for all of your contribution.
In future release of this library, may you add conversion from and to single primitive, not only array of primitive ?

Best Regards
 

kimble01

Member
Licensed User
Longtime User
If this is the wrong place to ask this I apologize, but I have a string of hex bytes coming over a serial connection:
"68FF30303030303235" when I use ByteConverter to parse this to bytes: conv.HexToBytes("68FF30303030303235") the resulting array at position 1 contains -1!
Shouldn't that be 255?

Thanks for the library, it's been truly useful.
 

raphaelcno

Active Member
Licensed User
Longtime User
when I use ByteConverter to parse this to bytes: conv.HexToBytes("68FF30303030303235") the resulting array at position 1 contains -1! Shouldn't that be 255?

A byte is shown as a value between -128 and +127, so FF (255) is shown as -1.
If you want to convert a byte to an integer value between 0 and 255, you can use this :
Dim Int_Byte As Int
Int_Byte = Bit.AND(0xff, Byte)
 
Top