Automating the world one-liner at a time…
I love the fact that we designed PowerShell for Admins and IT Pros and love to demonstrate what that means. Often I'll demo PowerShell and show how you can use "KB", "MB", and "GB" as I did in my previous blog entry:
PS> 1kb1024PS> 1mb1048576PS> 1gb1073741824PS> 1kb+2mb+3gb3223323648
Almost uniformly, the crowds LOVE this but every now and a again someone make the point that "kb" should be 1000 not 1024. One of our readers (Dan) made this point in comments to the last post and even provided a pointer to a Wikipedia article to back up his position. This is not an unreasonable position but I'll make 3 points:
Now if your head and heart are really into 1000, don't despair, PowerShell supports Scientific notion:
PS> 1e31000PS> 6e66000000PS> 1e1001E+100
We also support Hex format
PS> 0xFFFF65535PS> 0xCAB3243
And others. BTW - All of this is covered by Lee Holmes's O'Reilly BookWindows PowerShell Quick Reference. (Lee is a PowerShell developer and did a great job with this book.) This is the sort of book that you print out and keep next to your keyboard because you are always looking up something. On page 14, Lee shows you how you can convert to any numberbase (binary, octal, etc.)
Jeffrey Snover [MSFT]Windows PowerShell/MMC ArchitectVisit the Windows PowerShell Team blog at: http://blogs.msdn.com/PowerShellVisit the Windows PowerShell ScriptCenter at: http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx
Kb = 1000
KiB = 1024
At least in latest versions of their software Microsoft was able to teach users on this difference.
BTW, usage of kB as 1024 is forbidden by SI standard - http://www.bipm.org/utils/en/pdf/si-brochure.pdf (Section 3.1 CI Prefixes).
You have to respect standards.
Does PowerShell have a power operator? It would be more useful to be able to write 2**10, 2**20, 2**30, etc. than to special case those values.
FWIW, I agree that using KB/MB/GB in the historic sense rather than the technical sense is unfortunate. Admins and "IT Pros" (and Microsoft developers) only use the wrong terms because they don't know any better, and this will only serve to perpetuate ignorance and confusion (for example, when new hard drives - universally sold in gigabytes - are reported in gibibytes with the wrong suffix).
I'm with 1024 though I would have preferred to keep K, M etc as in the earlier versions
Hmm. 1kb is one kilobit. 1KB is one Kilobyte. What are we measuring here? Or is it all the same, numerically? (My brain turned off right about there.)
As for the 1000 part, you should have supported "k", as in "1k" = 1000, and "M" as in "1M" = 1000000.
That said, how would you accomplish that using extensibility? :)
> Does PowerShell have a power operator? It would be more useful to be able to write 2**10, 2**20, 2**30, etc. than to special case those values.
We don't have an operator, we use .NET:
> Hmm. 1kb is one kilobit. 1KB is one Kilobyte.
We are case-insensitive and in the end, there are no units - it is just an INT.
Jeffrey Snover [MSFT]
Windows PowerShell/Aspen Architect
Visit the Windows PowerShell Team blog at: http://blogs.msdn.com/PowerShell
Visit the Windows PowerShell ScriptCenter at: http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx
With all due respect, the distinction is important. The case of the "B" should indicate whether its bits or Bytes we're talking about. This base-1000 vs. base-1024 confusion is how hard drive manufacturers have always gotten away with murder in advertising their capacities. They define a Kilobyte as 1000-Bytes, etc...
Languages should allow programmers to concisely describe their intentions, not blur distinctions, causing the next-generation to scratch their heads looking at decades-old code. You have provided the world with a great service in creating this language, with from what I can tell, tremendous forethought. Please don't create these blurs. Correct this in the next release. Don't make it a holy cow or line in the sand.
While I don't agree with the case-insensitivity track taken with PowerShell, I can respect it's consistency with regard to other MS standards. Therefore, please consider a modification of the shorthand notation such as:
[Kk][Bb] = 1024 Bytes
[Kk][Bb][Ii][Tt] = 1000 bits
Thank you for your time, and consideration.
BTW, as a 16-year IT veteran and Systems Administrator for a wide variety of platforms over the years, from SunOS to HP/UX, to NT/Win2k3, to Linux, good job! We've badly needed what you've given us now with PowerShell.
For all us programmers and Admins who are using cmdlets. 1024 was the right choice. MS made a wise choice placing Jeffery at the helm. There will always be tradeoffs in a new product but time and again it seems to me the right decisions are being made to start out with. Version 2 will be tottaly complete and version 1 still rocks all in all a very good job in my opion for a very difficult task.
I agree with the 1kb = 1024 choice. But why did you only include kb, mb and gb ? tb's are getting more and more common these days - and what about pb/eb/zb/yb ?
> I agree with the 1kb = 1024 choice. But why did you only include kb, mb and gb ? tb's are getting more and more common these days - and what about pb/eb/zb/yb ?
"To ship is to choose." There is no good reason for these not to be there and we expect that they're there in a future release.
Windows PowerShell/MMC Architect
So far, what I have deduced is that 1024 is more comfortable a number than 1000 in the digital world.
This is because, a bit can be either logic 0 or logic 1. (FYI, a byte = 8 bits). Therefore a bit can have two states, or 2^1 states.
When you take three bits combined, they can have a total of 8 states or 2^3 states (000, 001, 010, 011,... 111).
So, if you take 10 bits, you get 2^10 = 1024 possible states. Now, this special number 2^10, that is 1024, is closest to 1000 as compared to 2^9 (512) and 2^11 (2048).
Therefore, they brought up the convention that 1024 = 1K. This makes things easier as if a RAM has capacity to hold 1024 bytes, you can use the 1024 states of a 3 bit input to tell the RAM, which byte of the RAM you want to access. But if it is only 1000, then the remaining 24 states are wasted!
Well what do you think? I know the digital mumbo jumbo may not make sense to some, but this sums up the whole thing of what I understand!
KB = 1024 as in capacity.
Kb = 1000 as in troughput.
it's all about case sensitivity, or in this case, case tolerance
Kb= 1024 bits
kb= 1000 bits
See the SI definitions @ nist.gov:
KiB = 1024
KB = 1000
actually, the hard-disk manufacturers are doing it right, the memory manufacturers are doing it wrong, they're selling more than they advertise, and windows is also doing it wrong, they advertise less than they have.
also, case does matter.
b = bit
B = Byte
kb = 1000 bit
kB = 1000 Byte
KiB = 1024 Byte
the SI prefixes should only be used in the decimal sense: kilobyte and megabyte denote one thousand bytes and one million bytes respectively, while kibibyte and mebibyte denote 1024 bytes and 1,048,576 bytes respectively. This recommendation has been adopted by SI, IEEE, CIPM, NIST, ISO/IEC and some other leading national and international standards, which now state that the prefixes k, M and G should always refer to powers of ten, even in the context of information technology. (reference: ISO/IEC IEC 80000-13:2008 )
IEC introduces unambigous prefixes for binary multiples (KiB, MiB, GiB etc.), reserving kB, MB, GB and so on for their decimal sense.
IEC prefixes are adopted by the IEEE after a two-year trial period.
NIST guidelines require use of IEC prefixes KiB, MiB ... (and not kB, MB) for binary byte multiples
p29, “The names and symbols for the prefixes corresponding to 2^10 , 2^20 , 2^30 , 2^40 , 2^50 , and 2^60 are, respectively: kibi, Ki; mebi, Mi; gibi, Gi; tebi, Ti; pebi, Pi; and exbi, Ei. Thus, for example, one kibibyte would be written: 1 KiB = 2^10 B = 1024 B, where B denotes a byte. Although these prefixes are not part of the SI, they should be used in the field of information technology to avoid the incorrect usage of the SI prefixes.”
also remember this:
decimal value binary value difference
1000^1 = 10^3 1024^1 = 2^10 2.4%
1000^2 = 10^6 1024^2 = 2^20 4.9%
1000^3 = 10^9 1024^3 = 2^30 7.4%
1000^4 = 10^12 1024^4 = 2^40 10.0%
1000^5 = 10^15 1024^5 = 2^50 12.6%
1000^6 = 10^18 1024^6 = 2^60 15.3%
1000^7 = 10^21 1024^7 = 2^70 18.1%
1000^8 = 10^24 1024^8 = 2^80 20.9%
also, this has a usability impact, since using the same wording with two different meanings is JUST PLAIN WRONG, and should end RIGHT NOW, Regular users don't know that the units have dual meanings, and we shouldn't continue confusing them in this way.
also "man 7 units" on linux ;)
While I understand backwards compatibility with long-held inaccuracies, alexanderpas (above) is absolutely correct.
The ISO/IEC 80000-13:2008 standard is being adopted by law in many countries. At some point, there will be lawsuits or a lunar landing crash because of these sorts of decisions failing the public or scientists that rely on correct output.
Get over misconception and welcome the standards!