MIDI 7-Bit Byte Calculator
SYSEX or NRPN getting you down? You’ve come to the right place. MIDI Designer’s Byte Calculator is the way to get your conversions done and get on with your MIDI life.
Converts from 7-bit MIDI bytes to values, or from values to 7-bit MIDI bytes.
/*************************************************************************
*
* CONFUSION STUDIOS CONFIDENTIAL
* __________________
*
* [2010] - [2019] Confusion Studios LLC
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Confusion Studios LLC and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to Confusion Studios LLC
* and its suppliers and may be covered by U.S. and Foreign Patents,
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Confusion Studios LLC.
*/
function sanitize($text) {
return trim(htmlspecialchars($text, ENT_QUOTES, 'UTF-8'));
}
function sevenBitByte($value, $which) {
$value = $value >> ($which * 7) & 0x7f;
return $value;
}
$FORM_NONE = 0;
$FORM_BYTES_TO_VALUE = 1;
$FORM_VALUE_TO_BYTES = 2;
$formToProcess = $FORM_NONE;
$result = "";
if ($_REQUEST["midi_bytes"])
$formToProcess = $FORM_BYTES_TO_VALUE;
else if ($_REQUEST["number_of_bytes"])
$formToProcess = $FORM_VALUE_TO_BYTES;
$lsb_first = $_REQUEST["lsb_first"] == "on" ? true : false;
$bytes = array();
if ($formToProcess == $FORM_BYTES_TO_VALUE) {
$midi_bytes = sanitize($_REQUEST["midi_bytes"]);
$bytesExploded = explode(" ", $midi_bytes);
$bytes = array();
foreach ($bytesExploded as $piece) {
$int_val = intval(hexdec($piece));
if (is_int($int_val))
$bytes[] = $int_val;
}
$numberOfBytes = count($bytes);
} else if ($formToProcess == $FORM_VALUE_TO_BYTES) {
$sum = intval($_REQUEST["sum"]);
$numberOfBytes = intval($_REQUEST["number_of_bytes"]);
$bytes = array();
if ($lsb_first) {
for ($i=0; $i<$numberOfBytes; $i++) {
$byte = sevenBitByte($sum, $i);
$bytes[] = $byte;
}
} else {
for ($i=$numberOfBytes-1; $i>=0; $i--) {
$byte = sevenBitByte($sum, $i);
$bytes[] = $byte;
}
}
}
$sum = 0;
$bytesAsString = "";
$i = $lsb_first ? 0 : $numberOfBytes - 1;
foreach ($bytes as $byte) {
$bit_shifted = $byte<<($i * 7);
$sum += $bit_shifted;
$result = $result . ($i+1) . ") 0x" . dechex($byte) . " = " . $byte . " decimal (" . $bit_shifted . ")
";
$bytesAsString = $bytesAsString . "" . dechex($byte). " ";
if ($lsb_first)
$i += 1;
else
$i -= 1;
}
if ($sum == 0)
$sum = "";
$bytesAsString = strtoupper($bytesAsString);
?>
Bytes to Value
Value to Bytes
if ($result) { ?>Result
Total: 0 } ?>
