Code example for CRC32

Methods: getValue, update

0
   */ 
  public Value execute(Value... args) {
    String string = args[0].asString();
    // This function produces a 'standard' CRC-32 (IV -1, reflected polynomial, 
    // and final complement step). The CRC-32 of "123456789" is 0xCBF43926. 
    Checksum crc = new CRC32();
    byte[] b;
    try { 
      b = string.getBytes("UTF-8");
    } catch (UnsupportedEncodingException e) {
      throw new AssertionError("UTF-8 must be supported");
    } 
    crc.update(b, 0, b.length);
    // Note that we need to cast to signed int, but that's okay because the 
    // CRC fits into 32 bits by definition. 
    return literalConstant((int) crc.getValue(), args[0]);
  } 
}