Created
February 18, 2011 15:41
-
-
Save morganp/833833 to your computer and use it in GitHub Desktop.
integer to hex one hot code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def int_to_hex_binary_position( num, chars=8 ) | |
return "0x#{(2**num).to_s(16).rjust(chars,'0')}" | |
end | |
int_to_hex_binary_position( 0 ) | |
> 0x00000001 | |
int_to_hex_binary_position( 1 ) | |
> 0x00000002 | |
int_to_hex_binary_position( 2 ) | |
> 0x00000004 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment