# Byte (Bit Octet) - Computer storage Unit (8bit)

The byte is the smallest unit of computer storage and represents:

Computer storage capacity is measured in bytes.

In today’s large-capacity servers, gigabyte is more often used.

It implements the first concept of buffer as processing data bit by bit would be really slow. Computer are even going now further processing data at the word size (16/32/64)

## Management

### Id and Storage location

Accessing an individual byte frequently requires reading or writing a word at once

### Unit

You must use the binary notation for the computer resource (memory, disk)

• 100 Mb = 100 * 1024 * 1024 = 100 * 10242 = 104 857 600 byte
Decimal Binary
Value Si Value IEC JEDEC
1000 k kilo- 1024 Ki kibi- K kilo-
10002 M mega- 10242 Mi mebi- M mega-
10003 G giga- 10243 Gi gibi- G giga-
10004 T tera- 10244 Ti tebi-
10005 P peta- 10245 Pi pebi-
10006 E exa- 10246 Ei exbi-
10007 Z zetta- 10247 Zi zebi-
10008 Y yotta- 10248 Yi yobi-

### Conversion

Because a byte is just a binary number (of a maximum of length 8), all byte operations are binary operation.

#### Byte to Decimal Integer

A byte is also an integer between:

• 0 in bit: 00000000
• and 255 in bit: 11111111.

A byte is just a binary number of length 8

//parseInt(x, base)
let byteString = '10101101';
let byteInt = parseInt('10101101', 2);
console.log(byteInt)


#### Decimal Integer to Byte

A byte is a decimal integer between:

• 0 : the binary 0000000
• and 255: the binary 11111111

In Javascript:

let toByteStringFormat = function (byteInt) {
let byteString = byteInt.toString(2); // to string base 2
}

console.log('  0: '+toByteStringFormat(0));
console.log('100: '+toByteStringFormat(100));
console.log('255: '+toByteStringFormat(255));


Byte to hexadecimal means generally to go to integer before converting to the hexadecimal base (16)

In Javascript:

let byteStringToHexadecimal = function(byteString){
let byteInt = parseInt(byteString,2); // Byte is a number of base 2, we parse the string in base 2
return byteInt.toString(16).toUpperCase(); // Hexadecimal is a number of base 16
}
console.log('11111111 (255): '+byteStringToHexadecimal('11111111'));


#### Conversion table: Byte to Decimal Integer to Hex

All the conversion in a table where the binary column contains the byte.

#### Byte Array to Long

A byte array is an array of byte.

let byteArrayToLong = function(/*byte[]*/byteArray) {
let value = 0;
for ( let i = byteArray.length - 1; i >= 0; i--) {
value = (value * 256) + byteArray[i];
}
return value;
};
let longToByteArray = function(/*long*/long) {

let byteArray = [0, 0, 0, 0, 0, 0, 0, 0];

for ( let index = 0; index < byteArray.length; index ++ ) {
var byte = long & 0xff;
byteArray [ index ] = byte;
long = (long - byte) / 256 ;
}

return byteArray;
};


### Maximum Decimal by Number of Byte

The maximum decimal by number of Byte (N) is: $$2^{N*8}$$

Calculate it:

## How Large is a Trillion?

1 Kilobyte = 103 = 1000 bytes
1 Megabyte = 106 = 1,000,000 bytes
1 Gigabyte = 109 = 1,000,000,000 bytes
1 Terabyte = 1012 = 1,000,000,000,000 bytes
1 Petabyte = 1015 = 1,000,000,000,000,000 bytes
1 Exabyte = 1018 = 1,000,000,000,000,000,000 bytes
1 Zetabyte = 1021 = 1,000,000,000,000,000,000,000 bytes
1 Yottabyte = 1024 = 1,000,000,000,000,000,000,000,000 bytes

1 million seconds = 11.57 days
1 billion seconds = 31.6 years
1 trillion seconds = 31,688 years

1 million inches = 15.7 miles
1 trillion inches = 15,700,000 miles (30 round trips to the moon)

$1 million = <$ .01 for every person in U.S.
$1 billion =$ 3.64 for every person is U.S.
$1 trillion =$ 3,636 for every person in U.S.