IntegerBCDCodec implements BlockCodec<Integer> { @Override public Integer decode(byte[] data, int bitLength) throws BlockCodecException { if (data.length * 8 != bitLength) { throw new BlockCodecException("integer(BCD) decode failure. bit count of " + data + " bytes is not " + bitLength + "."); } try { return new Integer(ByteUtils.bcdValue(data)); } catch (Exception ex) { throw new BlockCodecException("integer(BCD) decode failure. " + ex.getMessage(), ex); } }  @Override Integer zeroValue(); @Override Integer decode(byte[] data, int bitLength); @Override byte[] encode(Integer data, int bitLength); @Override void reset(); @Override String getValueType();  }
@Test public void testDecode() throws Exception { IntegerBCDCodec codec = new IntegerBCDCodec(); Assert.assertEquals(182, codec.decode(new byte[] { (byte) 0x01, (byte) 0x82 }, 16), 0); Assert.assertEquals(9182, codec.decode(new byte[] { (byte) 0x91, (byte) 0x82 }, 16), 0); Assert.assertEquals(82, codec.decode(new byte[] { (byte) 0x00, (byte) 0x82 }, 16), 0); Assert.assertEquals(9100, codec.decode(new byte[] { (byte) 0x91, (byte) 0x00 }, 16), 0); }