2

With java time we got java.time.temporal.ChronoUnit with it constants like: MILLIS, SECONDS, HOURS etc. Is there something similar but for memory unit? For example somethin liek MemoryUnit with BYTES, KB, MB with easy conversion from each other?

Cherry
  • 31,309
  • 66
  • 224
  • 364
  • [JScience](http://jscience.org/api/javax/measure/unit/SI.html) seems to be able to handle metric system units well in general, and you could probably adapt something using it for memory without too much trouble. – Tim Biegeleisen Apr 18 '17 at 06:37
  • There is no out-of-the-box memory unit, and the other answer covers how to do such things manually. – eis Apr 18 '17 at 06:41
  • 1
    Contrary to time units, you can convert between (integral) memory units by using bit shifts, making it a lot easier to compute than time units (assuming a base of 1024 instead of 1000 as people usually do in CS). In order to convert from bytes to KB, use `bytes >> 10`, for bytes to MB use `bytes >> 20` and so on. – Tobias Apr 18 '17 at 06:50

0 Answers0