ryanhelms1

Javascript Byte Conversion Script

Sep 20th, 2013
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function formatSizeUnits(bytes) {
  2.     if ((bytes >> 40) & 0x3FF)
  3.         bytes = (bytes >>> 30) + '.' + (bytes & (4 * 0x3FF)) + ' TB';
  4.     else if ((bytes >> 30) & 0x3FF)
  5.         bytes = (bytes >>> 30) + '.' + (bytes & (3 * 0x3FF)) + ' GB';
  6.     else if ((bytes >> 20) & 0x3FF)
  7.         bytes = (bytes >>> 20) + '.' + (bytes & (2 * 0x3FF)) + ' MB';
  8.     else if ((bytes >> 10) & 0x3FF)
  9.         bytes = (bytes >>> 10) + '.' + (bytes & (0x3FF)) + ' KB';
  10.     else if ((bytes >> 1) & 0x3FF)
  11.         bytes = (bytes >>> 1) + ' Bytes';
  12.     else
  13.         bytes = bytes + 'Byte';
  14.     return bytes;
  15. }
Advertisement
Add Comment
Please, Sign In to add comment