binary - PHP - read 8 bit integers -
i have binary file 8 bit integers. have tried use php unpack() functions cant of arguments work 1 byte integers. have tried combine data dummy byte can use 'n'/'v' arguments. working windows machine this. function return array of integers based on string of 8 bit binary integers. code have tried below -
$dat_handle = "intergers.dat"; $dat_file = fopen($dat_handle, "rb"); $dat_data = fread($dat_file, 1); $dummy = decbin(0); $combined = $dummy.$dat_data; $result = unpack("n", $combined);
what looking char datatype. there 2 version of this, signed (lowercase c
) , unsigned (uppercase c
). use 1 that's correct data.
<?php $byte = unpack('c', $byte); ?>
also, if data file bunch of bytes , nothing else, , know it's length, can this. (if length 16 signed chars in row.)
<?php $bytes = unpack('c16', $byte); ?>
if don't know how many bytes in file, know there going bytes can use asterisk code read until eof.
<?php $bytes = unpack('c*', $byte); ?>
Comments
Post a Comment