Module: ByteOrder

Defined in:
lib/byteorder.rb

Constant Summary collapse

Native =
:Native
BigEndian =
Big = Network = :BigEndian
LittleEndian =
Little = :LittleEndian

Class Method Summary collapse

Class Method Details

.big?Boolean

Returns:

  • (Boolean)

26
27
28
# File 'lib/byteorder.rb', line 26

def big_endian?
  byte_order == BigEndian
end

.big_endian?Boolean

Returns:

  • (Boolean)

21
22
23
# File 'lib/byteorder.rb', line 21

def big_endian?
  byte_order == BigEndian
end

.byte_orderObject

examines the byte order of the underlying machine


7
8
9
10
11
12
13
# File 'lib/byteorder.rb', line 7

def byte_order
  if [0x12345678].pack("L") == "\x12\x34\x56\x78" 
    BigEndian
  else
    LittleEndian
  end
end

.byteorderObject

examines the byte order of the underlying machine


15
16
17
18
19
20
21
# File 'lib/byteorder.rb', line 15

def byte_order
  if [0x12345678].pack("L") == "\x12\x34\x56\x78" 
    BigEndian
  else
    LittleEndian
  end
end

.little?Boolean

Returns:

  • (Boolean)

25
26
27
# File 'lib/byteorder.rb', line 25

def little_endian?
  byte_order == LittleEndian
end

.little_endian?Boolean

Returns:

  • (Boolean)

17
18
19
# File 'lib/byteorder.rb', line 17

def little_endian?
  byte_order == LittleEndian
end

.network?Boolean

Returns:

  • (Boolean)

27
28
29
# File 'lib/byteorder.rb', line 27

def big_endian?
  byte_order == BigEndian
end