header image

How many bytes?

Posted by: | April 30, 2009 | No Comment |

I was playing around with PowerShell and started thinking about the kb, mb etc values and I realised I didn’t know what they really looked like.  1kb is 1024 but it gets very hazy after that. So how could I see the values stacked up

1kb,1mb,1gb,1tb,1pb | foreach{"$_".PadLeft(16)}

works.  We feed in the list of values. Pipe into foreach and use string substitution to display.  That will left justify the display.  By padding the left of the display with spaces we can effectively right justify the field to give


So now you know what the stack of xbytes looks like

We can also achieve the same effect using

1kb,1mb,1gb,1tb,1pb | foreach{"{0,16}" -f $_}

Hmm.. wonder how effort is involved to produce a Tower of Hanoi script from this

Technorati Tags: ,,
under: PowerShell original, PowerShellV2