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:

klaus

Expert
Licensed User
Longtime User
CodePageFile object

Hi Andrew,

I would be pleased having in the ByteConverter a CodePageFile object like in B4PPC. It would be intersting to read files encoded with the ANSI (1252) code page for the special characters.
Or, why not, in the StringUtils LoadCSV3 and SaveCSV3.

Best regards and thank you in advace.
 

alan1968

Active Member
Licensed User
Longtime User
hello ,

the result byte 2's complement is how to have it in pure binary
ex: FFH = 255

thx!
my code
....
string_data=mid(string_data,28,string_data.Length-27)
nb_data=string_data.Length/3
Log("data:" & string_data)
Log("nb:" & nb_data)
For i=0 To nb_data-1
hex=mid(string_data,1+3*i,3).Trim
Log("hex:>"&hex&"<")
Bytes=conv.HexToBytes(hex)
Log("Byte:"&Bytes(0))
Next
...

log:
** Activity (main) Resume **
** Activity (main) Create, isFirst = true **
data:03 ce 00 00 00 a1 00 00
nb:8
hex:>03<
data:3
hex:>ce<
data:-50
hex:>00<
data:0
hex:>00<
data:0
hex:>00<
data:0
hex:>a1<
data:-95
hex:>00<
data:0
hex:>00<
data:0
** Activity (main) Resume **
 

transittransist

New Member
Licensed User
Longtime User
byte array length

I use byteconverter library to convert byte values to hex string.
I send a udp packet("test" string) which is size 4 bytes. When I get it and convert to hex I see "74657374000000000000000000000.............." in the textbox. There is 8000 bytes, first 4 byte is ok, but I send 4 bytes, so why I see these zeros. my code is below;

Dim data() As Byte
data = PacketReceived.data
EditText6.Text = Conv.HexFromBytes(data)

PacketReceived.Length returns 4.
when I try to restrict byte array length with such a code:
Dim data(PacketReceived.Length) As Byte

nothing changes. Conv.HexFromBytes(data) returns "74657374000000000000000000000.............." again.

How can I get rid of this zeros?
 

transittransist

New Member
Licensed User
Longtime User
Can you post the complete code that converts the bytes to hex string?

I realize that my problem is about UDP library. When I checked the data length I saw the problem.

PacketReceived.Length 'returns 4

However,
PacketReceived.data.Length 'returns 8000

So, the problem is in UDP library. I have used string manipulation and get rid of zeros.

Thanks,
 

PaulR

Active Member
Licensed User
Longtime User
I am having a bit of trouble with the syntax necessary for this library. Could somebody please post an example of how to convert an integer value of -1 to a 32 bit sequence of bytes please?

And how would I append that to another Byte variable, or string?

Any assistance would be most appreciated!

Cheers

Paul

edit: nevermind, my issue is trying to send raw data without any encoding. I worked out the syntax and got a log of all the encoders, but there doesn't seem to be a "none" option.
 
Last edited:

bluedude

Well-Known Member
Licensed User
Longtime User
Permission to use libraries in an application

Hi,

I see you don't accept private messages so it is hard to ask permission to use libraries. Anyway, hereby my public request to use your libraries.

Hereby i'm asking you official permission to use the following libraries in commercial and non-commercial applications. I hereby also request how I should atrribute your work in a proper manner. My plan is to provide a separate list view with all the library developers of the libraries that I use.

Libraries to use
Byteconvertor
Dialogs

The current application I develop can be found here (in Dutch)

ThingsTank - Android applicatie
 

agraham

Expert
Licensed User
Longtime User
You've found the Creative Commons license I see. Your attribution plan looks fine to me. Any of my libraries utilising 3rd party code with different licensing conditions, basically Jpeg (GNU PL 2), SVG (Apache 2.0) and PageTurnView (Apache 2.0), mention this somewhere in the xml help.
 

bluedude

Well-Known Member
Licensed User
Longtime User
Alright, I will store a screenshot of this conversation for my own archiving purposes as a kind of confirmation/prove.

I want to handle all this stuff in a professional matter to prevent problems later on.

Cheers and thanks for the great work!
 
Top