Created
September 7, 2017 18:48
-
-
Save jnunemaker/87fb475129c0601fa72695afe912b02f to your computer and use it in GitHub Desktop.
sha256 hexdigest to number for use in mapping a string to a partition number (not consistent hashing, but just in simple hash => partition)
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
irb(main):001:0> require "digest" | |
=> true | |
irb(main):002:0> Digest::SHA256.hexdigest("asdf") | |
=> "f0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13b" | |
irb(main):003:0> Digest::SHA256.hexdigest("asdf").to_i(16) | |
=> 108959270400061671294053818573968651411470832267186275529291850190552309358907 | |
irb(main):004:0> Digest::SHA256.hexdigest("asdf").to_i(16).to_s(16) | |
=> "f0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13b" | |
irb(main):005:0> Digest::SHA256.hexdigest("asdf").to_i(16) % 10 | |
=> 7 | |
irb(main):006:0> Digest::SHA256.hexdigest("asdf").to_i(16) % 10 | |
=> 7 | |
irb(main):008:0> Digest::SHA256.hexdigest("asdf").to_i(16) % 10 | |
=> 7 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment