[Gambas-user] Endianness issue with Streams ?
Benoît Minisini
benoit.minisini at gambas-basic.org
Thu Feb 8 04:17:51 CET 2024
Le 07/02/2024 à 14:20, Laurent Carlier a écrit :
> Le mercredi 7 février 2024, 14:06:28 UTC+1 Benoît Minisini a écrit :
>> Le 07/02/2024 à 13:59, Laurent Carlier a écrit :
>>> While reading data from a file using Read function and changing endianness
>>> i found a somehow strange behavior.
>>>
>>> ----8<-----
>>>
>>> Dim $iValue As Integer
>>> Dim oFitFile As File
>>>
>>> oFitFile = Open "toto" For Read
>>> $iValue = Read #oFitFile As Short
>>> Print Hex$($iValue), $iValue
>>>
>>> ---->8-----
>>>
>>> Setting ByteOrder as Little endian gives:
>>> 5E9 1513
>>> Setting ByteOrder as Big endian gives:
>>> FFFFFFFFFFFFE905 -5883
>>>
>>>
>>> So is it expected or is it a bug ?
>>
>> What's strange?
>
> Ok, so it's the expected behavior :) Thanks. I thought hex representation
> should be truncated to 4 digits automatically as it's a short value (2 bytes).
>
> Thanks for the clarification.
>
OK, I didn't understood: Hex$() always returns a 64-bit hexadecimal
value so that things are reciprocal. I.e. `Val("&H" & Hex$(Value)) =
Value` and `Hex$(Val("&H" & Str)) = Str`. If Hex$() has been truncated,
it would not have been possible.
Regards,
--
Benoît Minisini.
More information about the User
mailing list