On Thu, Nov 17, 2016 at 11:37 AM, Stephen R. van den Berg srb@cuci.nl wrote:
Lance Dillon wrote:
Stdio.File fp;fp=Stdio.File(filename,"r");string str=fp->read(2);int res=array_sscanf(reverse(str),"%2c")[0];
Using %2c to read little endian probably only works on CPUs that are little endian to begin with.
To quote from sscanf() documentation:
"%c" Reads one character and returns it as an integer ("0101" makes 48, or '0', leaving "101" for later directives). Using the field width and endianness modifiers, you can decode integers of any size and endianness. For example "%-2c" decodes "0101" into 12592, leaving "01" fot later directives. The sign modifiers can be used to modify the signature of the data, making "%+1c" decode "รค" into -28.
"-" Supplying a minus sign toggles the decoding to read the data encoded in little-endian byte order, rather than the default network (big-endian) byte order.