note 114359 deleted from function.unpack by googleguy

From: Date: Wed, 12 Feb 2014 19:08:29 +0000
Subject: note 114359 deleted from function.unpack by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-198479@lists.php.net to get a copy of this message
Note Submitter: ian_channing at hotmail dot com ---- I had trouble finding anyone who could explicitly say how to convert a varbinary (SQL Server) database value into a array of signed integers, e.g. for a waveform. In SQL Server varbinary stores big-endian signed shorts. To pull this out I used the following: <?php $unsignedWaveform = unpack('n*', $binaryWaveform); $waveform = array_map('unsignedToSignedShort', $unsignedWaveform); function unsignedToSignedShort($short) { if ($short >= pow(2, 15)) { return $short -= pow(2, 16); } else { return $short; } } ?> The n* was the magic that splits the large binary into individual shorts in an array.

« previous php.notes (#198479) next »