

Returns the human-readable file size for an arbitrary, 64-bit file size Attribution is not necessary, but a vote on the post at stackoverflow would be appreciated. The code below is dedicated to the public domain under the Unlicense or CC0, whichever is most appropriate for your use. You can get a Visual Basic (VB.Net) version by using the C# to VB.Net Convertor Tool. Use this function to display a human-readable, user-friendly file size to your users.īelow is the human readable file size function source code. It returns the file size to three decimals followed by the abbreviation, like KB, MB, GB, etc. This is a highly optimized function to get the file size abbreviation in bytes for an arbitrary, 64-bit file size. myRepono's charges are based on gigabytes of usage, so for example you might pay $0.20 for 1 GB of data transfer, this means you are paying $0.20 to transfer over 1 billion bytes of data (over 8 billion bits).§ Home > Index > C and C# Programming C# Human Readable File Size Optimized Function We then calculate the costs of the data storage and transfer based on the amount of bytes. myRepono use bytes to calculate the size of the files we are storing and transferring. Note, many non-alphanumeric characters such as symbols and foreign language characters use multiple bytes.Ī kilobyte (KB) is 1024 bytes, a megabyte (MB) is 1024 kilobytes and so on as these tables demonstrate.

A document containing 100 characters would use 100 bytes (800 bits) - assuming the file didn't have any overhead (additional data about the file which forms part of the file). For example, to store the letter 'R' uses 1 byte, which is stored by the computer as 8 bits, '01010010'. a letter or number such as 'A', 'B' or '7') is stored as 1 byte.

8 bits are known as a byte, and it is bytes which are used to pass our information in it's basic form - characters. Put another way, a bit is either an 'on' or an 'off' which is processed by a computer processor, we represent 'on' as '1' and 'off' as '0'. A single letter or character would use one byte of memory (8 bits), two characters would use two bytes (16 bits). FAQ > Understanding file sizes (Bytes, KB, MB, GB, TB) A byte is a sequence of 8 bits (enough to represent one alphanumeric character) processed as a single unit of information.
