On 21.11.2013 19:44, Frank Westlake wrote:
>> Isn't the second "if" in each line unnecessary because it is overwritten
>> in the next line anyhow?
>
> Yes, but that isn't good programming procedure.
Why? It makes the code much better readable and I think, the
additional executed set command doesn't consume more time
than the removed if statement. If you worry about speed, you
maybe have to use if-else:
if %1 LEQ 1024 (set "unit=Bytes") else (
if %1 LEQ 1048576 (set "unit=KB") else (
if %1 LEQ 1073741824 (set "unit=MB") else (
if %1 LEQ 1099511627776 (set "unit=GB") else (
if %1 LEQ 1125899906842624 (set "unit=TB") else (
set "unit=such a big disk doesn't exist" )))))
>> Why not just remove the last 9 digits?
>
> That wouldn't be good programming procedure,
If you have a decimal number in ascii representation
and want to divide it by 1000, then it is a bad idea
to convert the string to an integer then dived it by
1000 and convert the result back to ascii. It is much
better to just remove the last 3 digits.
> That's true for SI, but there are other standards and you haven't asked
> which he is using. Here's Wikipedia's statement:
>
> The computer industry is possibly the only industry in which some SI
> prefixes have been given definitions inconsistent with the International
> System of Units (SI). JEDEC has redefined the prefixes kilo, mega and
> giga as powers of 1024 instead of 1000, but not tera or any larger
> decimal prefix. With an aim of avoiding confusion, the International
Do you really suggest to divide by 1024 for kB, by 1024^2 for MB, by
1024^3 for GB but by 1000^4 for TB? That doesn't make any sense .
Do you know of any harddisk manufacturer who doesn't use 1000^3
but 1024^3 for GByte.