Module: UInt24 Private

Defined in:
lib/diameter/u24.rb

Overview

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

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

Class Method Summary (collapse)

Class Method Details

+ (Fixnum) from_u8_and_u16(eightb, sixteenb)

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)



14
15
16
# File 'lib/diameter/u24.rb', line 14

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

+ ([Fixnum, Fixnum]) to_u8_and_u16(twentyfourb)

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 he top 8 and low 16 bits.



25
26
27
28
29
# File 'lib/diameter/u24.rb', line 25

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