Academic Company Events Community Support Solutions Products & Services Contact NI MyNI
358 ratings:
 3.56 out of 5   

How Do I Convert Bytes to Kilobytes, Megabytes, and Gigabytes?



Primary Software:
Primary Software Version: 7.1
Primary Software Fixed Version: N/A
Secondary Software: N/A

Problem:
Some functions, such as Volume Info return information in bytes. How do I properly convert bytes to kilobytes, megabytes, and gigabytes?

Solution:
There can be some confusion as to how many bytes a kilobyte actually represents. When referring to memory a kilobyte is not 1,000 bytes, but rather 1024 bytes (which is 2^10 bytes). This is because memory must increase in binary (or base two) increments. So to convert from bytes to kilobytes you would divide the number of bytes by 1024. See the table below for other prefixes.

Name Abbreviation Size
1 Nibble   4 Bits
1 Byte  B 8 Bits
1 Kilobyte
KB
2^10 = 1,024 Bytes
1 Megabyte
MB
2^20 = 1,048,576 Bytes
    = 1,024 Kilobytes (KB)
1 Gigabyte
GB
2^30 = 1,073,741,824 Bytes
    = 1,048,576 Kilobytes (KB)
    = 1,024 Megabytes (MB)
1 Terabyte
TB
2^40 = 1,099,511,627,776 Bytes
    = 1,024 Gigabytes (GB)

Note: kilo was borrowed from the base 10 system to represent 1024 in the base 2 system because where was not a prefix for it. Since that convention was established, there have arisen several alternate conventions and terms. However, these have not been accepted into the mainstream vocabulary. One convention is instead of kilo, mega, giga, and tera; to use kibi, mebi, gibi, and tebi as the prefixes for the binary system (meaning the powers of 2 - i.e. 1 kibibyte = 1024 bytes and 1 kilobyte = 1000 bytes). Another convention is to use a lower case letter for the prefix in the abbreviation to indicate that a power of 10 was used (i.e. 1 KB = 1024 bytes while 1 kB = 1000 bytes). It is also common for communication methods to state specification on a per bit basis instead of bytes and to use the base 10 use of the prefixes. Often times bits are abbreviated with a lower case 'b' and bytes with a capital 'B' (i.e. 1 Kbps is 1000 bits per second and 1 KB/s is 1024 bytes per second).

Related Links:
KnowledgeBase 16I374PV: What is the Precision Difference Between float and double Datatypes?

KnowledgeBase 2ASACHQO: What Representation Does LabVIEW Use for Various Data Types?

Attachments:





Report Date: 05/06/2003
Last Updated: 04/07/2016
Document ID: 2X5A8EQS

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
  1 2 3 4 5
Please Contact NI for all product and support inquiries.submit