JS Data Capacity Unit conversion (KB,MB,GB,TB)

Source: Internet
Author: User

The JS code is as follows:

var size = ' 8164674 '; function bytestosize (bytes) {    ifreturn ' 0 B ';     var // or 1024x768        sizes = [' B ', ' KB ', ' MB ', ' GB ', ' TB ', ' PB ', ' EB ', ' ZB ', ' YB '],        = Math.floor (Math.log (bytes)/ Math.lo G (k));     return (Bytes/math.pow (k, i)). Toprecision (3) + "+ Sizes[i];} Console.log (Bytestosize (parseint (size)));

Summarize

The next two storage units are described: Bits, bytes

Bit: "Bit" is the smallest unit of data in an electronic computer. The status of each bit can only be 0 or 1.

Word: "word" consists of a number of bytes, the number of bits is called word length, different grades of machines have different length of words. For example, a 8-bit machine, its 1 characters equals 1 bytes, and the word length is 8 bits.

KB: is 1024 bytes

MB: Is 1024 kb

GB: is 1024 MB

TB: is 1024 GB

Common conversion units 1, bit, and byte conversions

1 bit (bits or bit) equals 0.125B (byte byte)

1 B (byte byte) equals 8 bit (bit or bit)

2, megabytes and kilobytes

1KB (kilobyte kb) equals 0.0009765625 MB (MBytes)

1MB (MBytes) equals 1024KB (kilobyte KB)

3, megabytes and gigabytes

1MB (MBytes) equals L 0.0009765625 GB (Kbytes)

1GB (gigabyte) equals 1024MB (MBytes)

JS Data Capacity Unit conversion (KB,MB,GB,TB)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.