Skip to content

Instantly share code, notes, and snippets.

@morganp
Created February 18, 2011 15:41
Show Gist options
  • Save morganp/833833 to your computer and use it in GitHub Desktop.
Save morganp/833833 to your computer and use it in GitHub Desktop.
integer to hex one hot code
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