Created
January 30, 2009 19:18
-
-
Save jmhodges/55220 to your computer and use it in GitHub Desktop.
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
| # From http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/256730 | |
| module Endian | |
| def self.big? | |
| endianness == :big | |
| end | |
| def self.little? | |
| endianness == :little | |
| end | |
| def self.endianness | |
| x = 0xdeadbeef | |
| endian_type = { | |
| Array(x).pack("V*") => :little, | |
| Array(x).pack("N*") => :big | |
| } | |
| endian_type[Array(x).pack("L*")] | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment