Byte Array (multi-byte word)

Bytes

About

A byte array is any array of byte.

Library represents them generally as a multi-byte word with the possibility to change the endianess. See for instance, the Array Buffer in Javascript

Conversion

To Integer

To a integer data type

The algorithm is power based <MATH> \text{integer} = \text{byteN} . 256^{n-1} + \text{...} + \text{byte3} . 256 . 256 + \text{byte2} . 256 + \text{byte1} </MATH>

Example in Javascript with the function byteArrayToInteger that accepts an array of byte in string format or integer

let byteArrayToInteger = function(/*string[]|int[]*/byteArray) {
    let value = 0;
    let byteValue;
    let byteString;
    let byteInteger;
    for ( let i = 0; i < byteArray.length; i++) {
       byteValue = byteArray[byteArray.length-1-i];
       if (typeof(byteValue)  === 'string' || byteValue instanceof String){
           byteInteger = parseInt(byteValue,2);
       } else {
           byteInteger = byteValue;
       }
       value = byteInteger * Math.pow(256,i) +  value;
    }
    return value;
};
  • Usage
let byteArray = ['00000001','11111111']; 
/* As a byte is an integer from 0 to 255 in decimal, same as */
byteArray = [1,255]; 
console.log(byteArrayToInteger(byteArray)+" (ie 256+255)");
/** others **/ 
console.log(byteArrayToInteger(['10110000','11110011'])+" (ie 256*176+243)") 
  • Output:

Language

Javascript

See Javascript - Byte Array (ArrayBuffer / DataView)





Discover More
Cpu Moore Law Transistor
Bit String

A bit string is a string of Bit (ie an ordered sequence of 0’s and 1’s). In computer, this is: a multiple of byte stored in a byte array
Javascript - Byte Array (ArrayBuffer / DataView)

To manipulate a byte array, in javascript, you have: a ArrayBuffer that represents an array: of fixed amount of bytes (one element = 1 byte) of binary element known as typed object : Int8 / Uint8:...
Card Puncher Data Processing
Memory - Byte Order - (Endian-ness) of a Word

Storage of a word in memory of more than one byte (ie byte array) If each memory address of the memory array can store only a single byte, you need to split the word in multi-part one byte long. This...
Data System Architecture
What is a Key Value Database/Store?

A key-value database / store is a NoSQL database based on the key-value data that is stored in btree or map data structure. You store some data, called a value, inside a key. The data can later be...
What is a UUID - Universally Unique IDentifier - (also known as GUID) ?

UUID (Universally or Global Unique IDentifier) are generated identifiers that are guaranteed to be unique and avoid collision



Share this page:
Follow us:
Task Runner