vendor/bundle/ruby/2.7.0/gems/dnsruby-1.61.5/lib/dnsruby/resource/NSAP.rb
# ------------------------------------------------------------------------------
#  Usage:  str2bcd(STRING, NUM_BYTES)
# 
#  Takes a string representing a hex number of arbitrary length and
#  returns an equivalent BCD string of NUM_BYTES length (with
#  NUM_BYTES * 2 digits), adding leading zeros if necessary.
# ------------------------------------------------------------------------------
str2bcd(STRING, NUM_BYTES)
Takes a string representing a hex number of arbitrary length and
returns an equivalent BCD string of NUM_BYTES length (with
NUM_BYTES * 2 digits), adding leading zeros if necessary.
str2bcd ( STRING NUM_BYTES ) Takes a string representing a hex number of arbitrary length and returns an equivalent BCD string of NUM_BYTES length ( with NUM_BYTES * 2 digits ) adding leading zeros if necessary .
def str2bcd(s, bytes)
        retval = "";
        digits = bytes * 2;
        string = sprintf("%#{digits}s", s);
        string.tr!(" ","0");
        i=0;
        bytes.times do
          bcd = string[i*2, 2];
          retval += [bcd.to_i(16)].pack("C");
          i+=1
        end
        return retval;
      end
def str2bcd ( s , bytes ) retval = "" ; digits = bytes * 2 ; string = sprintf ( "%#{digits}s" , s ) ; string . tr! ( " " , "0" ) ; i = 0 ; bytes . times do bcd = string [ i * 2 , 2 ] ; retval += [ bcd . to_i ( 16 ) ] . pack ( "C" ) ; i += 1 end return retval ; end
Usage:  str2bcd(STRING, NUM_BYTES)
Takes a string representing a hex number of arbitrary length and
returns an equivalent BCD string of NUM_BYTES length (with
NUM_BYTES * 2 digits), adding leading zeros if necessary.
Usage : str2bcd ( STRING NUM_BYTES ) Takes a string representing a hex number of arbitrary length and returns an equivalent BCD string of NUM_BYTES length ( with NUM_BYTES * 2 digits ) adding leading zeros if necessary .
s
<not_specific>
bytes
<not_specific>