When I convert between 1GB to byte using online tools, I get different answers. For instance, using Google Convertor: 1GB=1e+9
while in another converter I get 1GB= 1073741824
. I suppose the unit is used in different fashion based on whether 1KB=1024B
or 1KB=1000B
(this is Google unit).
How can I know which unit my machine uses using a small C program or function? Does C have a macro for that? I want to do that as my program will possibly be run via various operating systems.
Gigabyte (GB) A gigabyte is 1,073,741,824 (230) bytes. 1,024 megabytes, or 1,048,576 kilobytes. 894,784 pages of plain text (1,200 characters).
The term gigabyte has a standard definition of 10003 bytes, as well as a discouraged meaning of 10243 bytes. The latter binary usage originated as compromise technical jargon for byte multiples that needed to be expressed in a power of 2, but lacked a convenient name.
In other words, there are 1,048,576 bytes in 1 megabyte according to the binary system which computers use. So one gigabyte is equal to 1,073,741,824 bytes in base 2. This also means that there are 1,024 megabytes in one gigabyte in binary system.
A gigabyte is about one billion bytes.
The two tools are converting two different units.
1 GB = 10^9
bytes while 1 GiB = 2^30
bytes.
Try using google converter with GiB
instead of GB
and the mystery will be solved.
The following will help you understand the conversion a little better.
Factor Name Symbol Origin Derivation Decimal
2^10 kibi Ki kilobinary: (2^10)^1 kilo: (10^3)^1
2^20 mebi Mi megabinary: (2^10)^2 mega: (10^3)^2
2^30 gibi Gi gigabinary: (2^10)^3 giga: (10^3)^3
2^40 tebi Ti terabinary: (2^10)^4 tera: (10^3)^4
2^50 pebi Pi petabinary: (2^10)^5 peta: (10^3)^5
2^60 exbi Ei exabinary: (2^10)^6 exa: (10^3)^6
Note that the new prefixes for binary multiples are not part of the International System of Units (SI). However, for ease of understanding and recall, they were derived from the SI prefixes for positive powers of ten. As shown in the table, the name of each new prefix is derived from the name of the corresponding SI prefix by retaining the first two letters of the SI prefix and adding the letters bi
.
There's still a lot of confusion on the usage of GB
and GiB
in fact very often GB
is used when GiB
should or was intended to be.
Think about the hard drives world:
Your operating system assumes that 1 MB
equals 1 048 576 bytes
i.e. 1MiB
. Drive manufacturers consider (correctly) 1 MB
as equal to 1 000 000
bytes. Thus if the drive is advertised as 6.4
GB (6 400 000 000 bytes
) the operating system sees it as approximately 6.1 GB 6 400 000 000/1 048 576 000
= ~6.1 GiB
Take a look at this for more info on prefixes for binary units and this on metric prefixes.
This is just a confusion of units. There are actually two prefixes G
for 10⁹
and Gi
for 2³⁰
. Bytes should usually be measured with the second, so the correct writing would be GiB
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With