Alonso Alonso -4 years ago 71
C Question

How to know the size a gigabyte?

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.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download