This article mainly introduces the PHP implementation of byte-byte conversion to KB, MB, GB, TB method, combined with an instance of PHP for the byte count of the conversion operation of the specific implementation method, involving the use of PHP mathematical operations related functions, the need for friends can refe
Today in doing a network audit log when required to export the report, there is a mail attachment file size, the database is bytes byte number, the request to convert to KB display, use the following function, quite to the force, special to share.
function Sizeformat ($bytesize) {$i = 0;When the $bytesize is greater than 1024 bytes, start the loop, when the loop jumps to the 4th time;while (ABS ($bytesize) >=1024) {$bytesize = $bytesize/1024;$i + +;if ($i ==4) break;}The BYTES,KB,
For example, when we refer to "data transfer speed" and "hard disk storage space", kilobytes represent 1000 (103), and when it comes to memory or CPU cache capacity, kilobytes represent 1024 (210) because they are stored here by byte-code address.
In practical applications, we often need to convert bytecode to KB, MB, GB, and so on, where we use JavaScript to convert bytecode:
The code is as f
The size of the computer stores information, the most basic unit is byte, a Chinese character consists of two bytes, letters and numbers are composed of a byte.
Units of capacity are from small to large: bytes (B), KB, MB, GB, TB. The relationship between them is.
1tb=1024gb
1gb=1024mb
1mb=1024kb
1kb=1024 bytes
Usually people use the simple name, the back of the "B" removed, so you ask the 1GB is 1024
recursively, and then calculates their size and that is the entire file directory.
Because the file size that is returned directly is in bytes, we generally have to convert to the size we usually get, and here is the function of the unit conversion:
The code is as follows
Copy Code
function Sizeformat ($size){$sizeStr = ';if ($size {return $size. "bytes";}else if ($size {$size =round ($size/1024,1);return $size. " KB ";}
, pronounced "Y-byte"There are also legends.1NiB (Nonabyte) =1024yib, which is 2 of 90 square bytes1DiB (Doggabyte) =1024nib, which is 2 of 100 square bytes1CiB (Corydonbyte) =1024dib, which is 2 of 110 square bytesNote: A lot of information on the Internet has the nib and Dib reversed. NB is not the largest, more than NB is the db, haha! And the bigger is CB.We must see Icech above is not the title of the Mb/gb
What is the storage unit of a computer?
Computer storage units are generally expressed in bit, Byte, KB, MB, GB, TB, PB, EB, ZB, BB,
We often refer to the byte abbreviation as B and ask K for the KB abbreviation. What a few k, what a few B.
Two, what is their conversion relationship? 1, the smallest unit in which the computer stores information: bit bit (
The smallest base unit is byte. Not many people do not know, the following first in order to give all units
Byte, KB, MB, GB, TB, PB, EB, ZB, YB, DB, NB
I only know the top five, and most people know that, according to the rate of 1024 calculation
40 1tb=2 byte=1099511627776 Byte of the second order
1pb=2 's 50-time Square Byte=1125899906842624byte
60 1eb=2 byte= 1152921504606846976 Byte of the second order
1 TB = 1024 GB 1 GB = 1024 MB 1 MB = 1024kb 1kb = 1024 byte note: byte means B, that is, byte KB is a kilobytes of MB, that is, GB is a Gigabit, that is, a gigabit. Generally, they can be viewed as a kilobytes of data, the accurac
The size of the php statistics file, which is measured in GB, MB, KB, and B. Use the filesize () function command to calculate the file size. the value 1 must be an output of GB, MB, KB, and B. 2. the order of magnitude must be greater than 1 and less than 1024, and two decimal places must be retained. use the filesize
, that is, the 70-power byte of 2, the pronunciation of "Z Byte"1yib (yottabyte) = 1024zib, that is, the power byte of 2, the pronunciation of "y Byte"
Legend has it that
1nib (nonabyte) = 1024yib, that is, the 90-power byte of 21dib (doggabyte) = 1024nib, that is, the 100 power byte of 21cib (corydonbyte) = 1024dib, that is, the 100 power byte of 2
Note: many materials on the Internet have reversed nib and DiB. NB is not the largest. dB is better than Nb. Haha! The bigger one is CB.
We can see
In the computer newspaper, the Dutch bank's 20 data centers have about 7PB of disk and more than 20PB of tape storage, and the annual growth of 50%~70% reserves,
So want to see how much PB, calculate 27pb about 400,000 80 of the hard disk size.
1Byte = 8 Bit (0,1)
1 KB = 1,024 Bytes (size of a shortcut)
1 MB = 1,024 KB = 1,048,576 Bytes (size of a floppy disk)
1 GB = 1,024
Having stayed at school, I went over PhP and looked at the previously written functions. I suddenly wanted to write the known file size and sort the data.
For example: 1.3G, 153 MB, 458kb, 998 m, 0.99g (the difference between MB and MB is not considered here, and generally does not involve the operation of MB, so
I learned the fread reading command and used the filesize function. when I knew that this function was useful, I used it to compile the statistics file size function and used the filesize () function command to collect statistics on the file size, requirements: 1, with one output in GB, MB, KB, and B; 2. the order of magnitude must be greater than 1 and less than 1024, and two decimal places must be retaine
How can we sort 10 GB files (one number per row) in MB of memory? How can I find 10 GB files? How does one calculate the number of times each keyword appears in a 10g File? How does one sort 10G files by MB in memory (one number per line? How can I find 10 GB files? How to c
Android get folder, file size in B, KB, MB, GBpublic class Filesizeutil {public static final int sizetype_b = 1;//Gets the double value of file size unit B public static final int sizety pe_kb = 2;//Gets the file size in kilobytes of double value public static final int sizetype_mb = 3;//Gets the file size unit to MB Double value public static final int sizety PE_GB = 4;//Gets the file size unit is a double
In the computer newspaper, the Dutch bank's 20 data centers have about 7PB of disk and more than 20PB of tape storage, and the annual growth of 50%~70% reserves,So want to see how much PB, calculate 27pb about 400,000 80 of the hard disk size.1Byte = 8 Bit1 KB = 1,024 Bytes1 MB = 1,024 KB = 1,048,576 Bytes1 GB = 1,024 MB = 1,048,576 KB = 1,073,741,824 Bytes1 TB =
PHP implements the original method of converting Byte to KB, MB, GB, and TB.
This example describes how to convert the number of bytes in PHP to KB, MB, GB, or TB. We will share this with you for your reference. The details are as follows:
The previous section describes how to convert the number of bytes in java to KB,
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.