Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The author's lookup table is incorrect.

The question being answered clearly wanted base2 engineering prefix units, rather than the standard base10 engineering prefix units.

suffixes = [ "EB", "PB", "TB", "GB", "MB", "KB", "B" ]

magnitudes = [ 2^60, 2^50, 2^40, 2^30, 2^20, 2^10, 2^0 ] // Pseudocode, also 64 bit integers required. (Compilers might assume unsigned 32 for int)



That is not the author's code. That is pseudocode for one of the example answers that he is improving on.

The author's code gives an option for the units:

int unit = si ? 1000 : 1024;


If you do this you should add an 'i' to the prefixes to denote that you mean the binary notation. e.g: kiB, MiB, GiB, TiB, etc


That code snippet is explicitly introduced in the article as not the author's.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: