You already have a capture group for the device prefix, now you only need a lookup table:
{ 'k', 1L<<10 }, { 'M', 1L<<20 }, { 'G', 1L<<30 }, { 'T', 1L<<40 }, { 'P', 1L<<50 }, { 'E', 1L<<60 }
Demo: http://ideone.com/5O7Vp
Although 1258291 clearly too many significant digits to get from 1.2MB .
oops, I gave an example of C #. The method is still good.
Ben voigt
source share