Bytes

WARNING: Use Rich Units package for future compatibilty!

Synopisis

Additional methods for Numeric class to make working with bits and bytes easier.

Additional methods for Numeric class to make working with bits and bytes easier. Bits are used as the base value and these methods can be used to convert between different magnitudes.

  1.byte               #=> 8
  2.bytes              #=> 16
  1.kilobit            #=> 1024
  1.kilobyte           #=> 8192

Use the in_* methods to perform the inverse operations.

  8192.in_kilobytes    #=> 1
  1024.in_kilobits     #=> 1

History

Special thanks to Richard Kilmer for the orignal work. This library is based on the original library bytes.rb Copyright (c) 2004 by Rich Kilmer.

Also thanks to Alexander Kellett for suggesting it be included in Facets.

Authors

  • Rich Kilmer
  • Thomas Sawyer

NOTES

This library is not compatible with STICK‘s units.rb (an spin-off of Facets old units.rb library). Do not attempt to use both at the same time.

Todo

  • Currently kilo, mega, etc. are all powers of two and not ten, which technically isn‘t corrent even though it is common usage.
  • The in_* notation is weak. If a better nomentclature is thought of then consider changing this.

Copying

Copyright (c) 2005 Rich Kilmer

Ruby License

This module is free software. You may use, modify, and/or redistribute this software under the same terms as Ruby.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.