How to convert Hex values in file to number or string

HARRY

Active Member
Licensed User
Longtime User
Hi,

In a file there are some (1 to 4) consequetive bytes that form together a hex value. That file results from another program, not a Basic4PPC program. I do not succeed to make calculations with that data.

I read the relevant part of the file, opened with cRandom, into a variable. Using SubString to isolate the bytes concerned results into a message 'The XML was improperly formatted'.

I tried several things, but no result. Am I overlooking something? What is the proper way to do that?

Harry
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Which version of Basic4ppc do you use?
'The XML was improperly formatted' is an IDE bug that was fixed in V6.00.

You should read the bytes with FileGetByte or with the BinaryFile library.
Afterwards you will need to do a small calculation to get the number value.
Something like (if the value is written in two bytes and the first byte is the lower byte):
B4X:
b1 = FileReadByte(c,pos)
b2 = FileReadByte(c,pos+1)
number = b1 + 256 * b2
 
Top