Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert 1000 to 1024 bytes

Tags:

linux

shell

I am trying to convert a size, let's say 244410368 bytes to xxxxxx megabytes (MB) but I have no idea how to do this.

I find the idea of 1000 and 1024 bytes/bits rather confusing.

like image 661
Mint Avatar asked Nov 29 '22 04:11

Mint


2 Answers

Although unit conversion isn't terribly complicated math, reducing the number of hard-coded numbers and shell-scripting the idea (rather than the computation) may be desireable. If your linux system has the units program, you can do unit conversions like this:

% units --terse "244410368 bytes" "MiB"
233.08789

% units --terse "244410368 bytes" "MB"
244.41037

(On Ubuntu, the units program is provided by the (surprise!) units package.)

like image 179
unutbu Avatar answered Dec 06 '22 10:12

unutbu


The de-facto size for a byte is 8 bits, so to convert a number of bytes into a number of bits, just multiply by 8.

like image 45
Greg Beech Avatar answered Dec 06 '22 09:12

Greg Beech