code: public static byte[] toBcd(String address) throws NullPointerException, IllegalArgumentException {
          if (address == null) {
              throw new NullPointerException("Address cannot be null for BCD encoding");
          }
  
          if (!StringUtil.containsOnlyDigits(address)) {
              throw new IllegalArgumentException("Address must only contain digits");
          }
  
          // make sure this address is always an even length
          if (address.length() % 2 != 0) {
              // add an extra F onto the end
              address = address + "F";
          }
  
          // calculate length of final byte[]
          int bytes_len = address.length() / 2;
          byte[] bcd = new byte[bytes_len];
  
          for (int i = 0; i < bytes_len; i++) {
              StringBuilder chunk = new StringBuilder(address.substring(i * 2, (i * 2) + 2));
              // reverse the digits since its BCD encoded
              chunk.reverse();
              // get the byte
              byte[] bytes = HexUtil.toByteArray(chunk.toString());
              //byte[] bytes = ByteUtil.decodeHex(chunk.toString(), 2);
              // add this byte onto our total
              bcd[i] = bytes[0];
          }
  
          return bcd;
      }
docs: Converts an address to a BCD-encoded byte array.  Any odd-length address
  such as "10950" will have an 0xF byte added as the most signification
  digit onto the end.  Used inside PDUs to encode addresses.  For example,
  "10950" will look like this byte[] afterwards [0x01 0x59 0xf0].
  @param address The address to encode such as "10950" or "13135554272"
  @return A BCD-encoded byte array such as [0x01 0x59 0xf0] for "10950" or
  [0x31 0x31 0x55 0x45 0x72 0xf2] for "13135554272".  Will return a
  zero-length byte[] for an empty address.
  @throws NullPointerException If the address is null
  @throws IllegalArgumentException If the address does not contain only digits