ryanhelms1 icon

Javascript Byte Conversion Script

ryanhelms1 | PRO | 09/20/13 05:50:19 PM UTC | 0 ⭐ | 288 👁️ | Never ⏰ | []
JavaScript |

530 B

|

None

|

0 👍

/

0 👎

function formatSizeUnits(bytes) {
    if ((bytes >> 40) & 0x3FF)
        bytes = (bytes >>> 30) + '.' + (bytes & (4 * 0x3FF)) + ' TB';
    else if ((bytes >> 30) & 0x3FF)
        bytes = (bytes >>> 30) + '.' + (bytes & (3 * 0x3FF)) + ' GB';
    else if ((bytes >> 20) & 0x3FF)
        bytes = (bytes >>> 20) + '.' + (bytes & (2 * 0x3FF)) + ' MB';
    else if ((bytes >> 10) & 0x3FF)
        bytes = (bytes >>> 10) + '.' + (bytes & (0x3FF)) + ' KB';
    else if ((bytes >> 1) & 0x3FF)
        bytes = (bytes >>> 1) + ' Bytes';
    else
        bytes = bytes + 'Byte';
    return bytes;
}

Comments