Module: Diameter::Internals::UInt24

Defined in:
lib/diameter/u24.rb

Overview

Methods for handling 24-bit unsigned integers, used for length and Command-Codes but not representable by String#unpack or Array#pack.

Class Method Summary collapse

Class Method Details

.from_u8_and_u16(eightb, sixteenb) ⇒ Fixnum

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Generates an unsigned integer from two other unsigned integers (one representing the top 8 bits, one representing the bottom 16 bits).

Parameters:

  • eightb (Fixnum)

    The top 8 bits (max 255)

  • sixteenb (Fixnum)

    The low 16 bits (max 2^16-1)

Returns:

  • (Fixnum)

    (max 2^24-1)



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

def self.from_u8_and_u16(eightb, sixteenb)
  (eightb << 16) + sixteenb
end

.to_u8_and_u16(twentyfourb) ⇒ [Fixnum, Fixnum]

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Converts an unsigned integer to two other unsigned integers (one representing the top 8 bits, one representing the bottom 16 bits).

Parameters:

  • twentyfourb (Fixnum)

    The original number (max 2^24-1)

Returns:

  • ([Fixnum, Fixnum])

    Separate integers representing the top 8 and low 16 bits.



29
30
31
32
33
# File 'lib/diameter/u24.rb', line 29

def self.to_u8_and_u16(twentyfourb)
  top_eight = twentyfourb >> 16
  bottom_sixteen = twentyfourb - (top_eight << 16)
  [top_eight, bottom_sixteen]
end