Project

hex_values

0.0
No commit activity in last 3 years
No release in over 3 years
Add functionality to get hexadecimal values from float and float from a string hexadecimal
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

HexValues

Gem Version Code Climate Build Status Coverage Status

Transform your float to hexadecimals and viceversa!

Installation

Add this line to your application's Gemfile:

gem 'hex_values'

And then execute:

$ bundle

Or install it yourself as:

$ gem install hex_values

Usage

require the gem:

require 'hex_values'

And then transform any float to a hexadecimal:

234.25.to_hex
# => "EA.4"

Or transform any hexadecimal to the corresponding float:

"EA.4".to_float
# => 234.25

Hexadecimal

To be more precise, when you transoform a Float (or a Fixnum) to an hexadecimal, you get a Hexadecimal object. This object is a representation of the Hexadecimal value, and you can operate on this object:

hexa = 234.25.to_hex
result = hexa + 234.25
result.to_s
# => "1D4.8"

also you can operate over a Float (or a Fixnum) using an Hexadecimal value.

hexa = 234.25.to_hex
result = 234.25 + hexa # I know, this is obvious...but is better to explain that works.
result.to_s
# => "1D4.8"

So far, the operations availables are:

  • plus (+)
  • minus (-)
  • multiply (*)
  • division (/)
  • Power (**)

From float to Hex

The "to_hex" method allows a precision parameter to set the maximum number of decimals to calculate (default 14).

Bear in mind that the larger the number, the larger the amount of time used to get the number:

1875.37.to_hex(50)
# => 753.5EB851EB851EB851EB851EB851EB851EB851EB851EB851EB85

Supported Ruby versions

This gem is tested with:

  • ruby 1.9.2
  • ruby 1.9.3
  • ruby 2.0.0
  • JRuby 1.9
  • Rubinius 1.9

Contributing

There are many, many ways to contribute to this project...but I will only explain two 😄

Forking the project

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Creating an issue

Go to the issue tab and create a new issue explaining what is happening and what it the expected behaviour.