File Storage Capacity

File storage capacity is usually shown by multiple of bytes. The following table shows the multiple of bytes from KB to YB.­­­­ Writing a simple algorithm to convert a Byte value to an appropriate KB, MB…YB value can be achieved by divding the byte value by 1024.

 

 

 

 

 

 

How to Convert Bytes to KB, MB… YB?

The conversion is simple. The byte value should be divided by 1024 while is greater than 1024 (KB).

do { bytes /= 1024; index++; }
            while (bytes >= 1024);

The following code can be used to retrieve the total size of each drive and depends on the size, the output will be formatted to the closest byte value such as GB, TB, and so on.

 

 

 

 

 

 

 

 

 

 

 

 

The output is shown below:

Copyright © All Rights Reserved - C# Learners