You are currently viewing the GMLscripts.com static mirror. Forum access and script submissions are not available through this mirror.

Invert GMLscripts.com

file_bin_read_word

Returns a word value of a given byte-size from an open binary file.

//  test.dat contents: 07 5B CD 15 15 CD 5B 07
fid = file_bin_open("test.dat", 0);
word = file_bin_read_word(fid, 4, true));  //  word == 123456789
next = file_bin_read_word(fid, 4, false)); //  next == 123456789
file_bin_close(fid);
file_bin_read_word(file,size,bigend)
Returns a word value of a given byte-size from an open binary file.
COPY/// file_bin_read_word(file,size,bigend)
//
//  Returns a word value of a given byte-size from an open binary file.
//
//      file        file id of an open binary file, real
//      size        size of the word in bytes, real
//      bigend      true to use big-endian byte order (MSB first), bool
//
/// GMLscripts.com/license
{
    var file,size,bigend,value,i,b;
    file = argument0;
    size = argument1;
    bigend = argument2;
    value = 0;
    for (i=0; i<size; i+=1) {
        b[i] = file_bin_read_byte(file);
    }
    if (bigend) for (i=0; i<size; i+=1) value = value << 8 | b[i];
    else for (i=size-1; i>=0; i-=1) value = value << 8 | b[i];
    return value;
}

Contributors: Leif902, xot

GitHub: View · Commits · Blame · Raw