Calculates CRC from an int
3674
public static int generateInt32(int crc, int value)
  {
    crc = next(crc, (value >> 24));
    crc = next(crc, (value >> 16));
    crc = next(crc, (value >> 8));
    crc = next(crc, (value >> 0));

    return crc;
  }
475474
private static long getCRC(InputStream is) throws IOException {
        CheckedInputStream check = new CheckedInputStream(is, new CRC32());
        BufferedInputStream in = new BufferedInputStream(check);
        while (in.read() != -1) {
            // Read file in completely
        }
        long crc = check.getChecksum().getValue();
        return crc;
    }
1087679
private static int calcOcc(Alternative ab, boolean calcMax, AgBuffer cb) {
        int occ;
        int i;
        int max;
        State state;

        occ = 0;
        max = ab.getArgCount();
        for (i = 0; i < max; i++) {
            state = cb.lookup(ab.getArgAttribute(i));
            if (state != null) {
                occ += (calcMax)? state.maxOcc : state.minOcc;
            } else {
                occ += 1;
            }
        }
        return occ;
    }
788781
private static int extractInt(byte[] arr, int offset) {
        return ((arr[offset] & 0xFF) << 24) | ((arr[offset + 1] & 0xFF) << 16) | ((arr[offset + 2] & 0xFF) << 8)
                | (arr[offset + 3] & 0xFF);
    }
1235534
def crc8(data):
        
        crc = 0

        for byte in data:
            crc ^= byte
            for _ in range(8):
                if crc & 0x01:
                    crc = (crc >> 1) ^ 0x8C
                else:
                    crc >>= 1
                crc &= 0xFF
        return crc
105153
private void xdr_int(int i) {
    buffer[offset++] = (byte)((i >> 24) & 0xff);
    buffer[offset++] = (byte)((i >> 16) & 0xff);
    buffer[offset++] = (byte)((i >> 8) & 0xff);
    buffer[offset++] = (byte)(i & 0xff);
  }
1201628
function crc32(png, offs, size) {
					var crc = -1;
					for (var i = 4; i < size-4; i += 1) {
						crc = _crc32[(crc ^ png[offs+i].charCodeAt(0)) & 0xff] ^ ((crc >> 8) & 0x00ffffff);
					}
					write(png, offs+size-4, byte4(crc ^ -1));
				}
531448
def accumulate(self, buf):
        ''''''
        accum = self.crc
        for b in buf:
            tmp = b ^ (accum & 0xff)
            tmp = (tmp ^ (tmp<<4)) & 0xFF
            accum = (accum>>8) ^ (tmp<<8) ^ (tmp<<3) ^ (tmp>>4)
        self.crc = accum
1335080
static final int crc8(final byte[] input, final int offset, final int len) {
		final int poly = 0x0D5;
		int crc = 0;
		for (int i = 0; i < len; i++) {
			final byte c = input[offset + i];
			crc ^= c;
			for (int j = 0; j < 8; j++) {
				if ((crc & 0x80) != 0) {
					crc = ((crc << 1) ^ poly);
				} else {
					crc <<= 1;
				}
			}
			crc &= 0xFF;
		}
		return crc;
	}
444701
static public short getCRC(byte[] buf, int len)
	{
		short i;
		short crc = 0x7fff;
		boolean isNeg = true;

		for(int j = 0; j < len; j++) {
			crc ^= buf[j] & 0xff;

			for (i = 0; i < 8; i++) {
				if ((crc & 1) == 0) {
					crc >>= 1;
					if (isNeg) {
						isNeg = false;
						crc |= 0x4000;
					}
				} else {
					crc >>= 1;
					if (isNeg) {
						crc ^= 0x4408;
					} else {
						crc ^= 0x0408;
						isNeg = true;
					}
				}
			}
		}

		return isNeg ? (short) (crc | (short) 0x8000) : crc;
	}
881974
function calculateBitsValueByCycleIndex( oConn, uCycleIndex, pfnCallback )
{
	if ( ! oConn )
	{
		return pfnCallback( `call calculateBitsValueByCycleIndex with invalid oConn` );
	}
	if ( 'number' !== typeof uCycleIndex || uCycleIndex < 1 )
	{
		return pfnCallback( `call calculateBitsValueByCycleIndex with invalid uCycleIndex` );
	}

	let nAverageBits;
	let nTimeUsed;
	let nTimeStandard;

	//
	//	return bits value of cycle 1,
	//	if uCycleIndex <= _constants.COUNT_CYCLES_FOR_DIFFICULTY_DURATION
	//
	if ( uCycleIndex <= _constants.COUNT_CYCLES_FOR_DIFFICULTY_DURATION + 1 )
	{
		return queryBitsValueByCycleIndex
		(
			oConn,
			1,
			function( err, nBits )
			{
				if ( err )
				{
					return pfnCallback( err );
				}

				return pfnCallback( null, nBits );
			}
		);
	}

	//	...
	_async.series
	([
		function( pfnNext )
		{
			_round.getAverageDifficultyByCycleId
			(
				oConn,
				uCycleIndex - 1,
				function( nBits )
				{
					nAverageBits = nBits;
					return pfnNext();
				}
			);
		},
		function( pfnNext )
		{
			//	in seconds
			_round.getDurationByCycleId
			(
				oConn,
				uCycleIndex - 1,
				function( nTimeUsedInSecond )
				{
					console.log( `%%% _round.getDurationByCycleId, nTimeUsedInSecond = ${ nTimeUsedInSecond }` );

					//	...
					if ( 'number' === typeof nTimeUsedInSecond &&
						nTimeUsedInSecond > 0 )
					{
						//
						//	to be continued ...
						//
						nTimeUsed = nTimeUsedInSecond;
						return pfnNext();
					}
					else
					{
						//
						//	STOP HERE,
						//	return bits value of previous cycle
						//
						return queryBitsValueByCycleIndex
						(
							oConn,
							uCycleIndex - 1,
							function( err, nBits )
							{
								if ( err )
								{
									return pfnNext( err );
								}

								//	...
								//	bits of previous cycle
								//
								return pfnCallback( null, nBits );
							}
						);
					}
				}
			);
		},
		function( pfnNext )
		{
			//
			//	in seconds
			//
			nTimeStandard = _round.getStandardDuration();
			return pfnNext();
		}
	], function( err )
	{
		if ( err )
		{
			return pfnCallback( err );
		}

		//
		//	calculate next bits
		//
		_pow_miner.calculateNextWorkRequired
		(
			nAverageBits,
			nTimeUsed,
			nTimeStandard,
			function( err, oData )
			{
				//
				//	oData
				//	{ bits : uNextBits }
				//
				if ( err )
				{
					return pfnCallback( err );
				}

				if ( oData &&
					'object' === typeof oData )
				{
					if ( oData.hasOwnProperty( 'bits' ) &&
						'number' === typeof oData.bits &&
						oData.bits > 0 )
					{
						pfnCallback( null, oData.bits );
					}
					else
					{
						pfnCallback( `calculateNextWorkRequired callback :: invalid value .bits, oData = ${ JSON.stringify( oData ) }` );
					}
				}
				else
				{
					pfnCallback( `calculateNextWorkRequired callback :: invalid oData object` );
				}
			}
		);
	});
}
517589
def _int_size(x):
    """"""
    if -0x80 <= x <= 0x7F:
        return 1
    elif -0x8000 <= x <= 0x7FFF:
        return 2
    elif -0x80000000 <= x <= 0x7FFFFFFF:
        return 4
    elif long(-0x8000000000000000) <= x <= long(0x7FFFFFFFFFFFFFFF):
        return 8
    else:
        raise RuntimeError("Cannot represent value: " + str(x))
208784
def inttoDER(a):
    '''
    
    '''

    o = dechex(a,1)
    if int(o[:2],16) > 127:
        o = '00' + o
    olen = dechex(len(o)//2,1)
    return '02' + olen + o
1081576
private static function crc16(string $hexChars): int
    {
        $chars = hex2bin($hexChars);
        if ($chars) {
            $crc = 0x1D0F;
            for ($i = 0; $i < strlen($chars); $i++) {
                $x = ($crc >> 8) ^ ord($chars[$i]);
                $x ^= $x >> 4;
                $crc = (($crc << 8) ^ ($x << 12) ^ ($x << 5) ^ ($x)) & 0xFFFF;
            }
        } else {
            $crc = 0;
        }
        return $crc;
    }
299525
function lockCrc(inputStr){

		res = 0xff;
		inputHex = new Buffer(inputStr,'hex');

		//start from the second byte 
		for (i = 1; i<= inputHex.length; i++) {
			res = res ^ inputHex[i];
		}
		//add padding
		reshex = (res+0x100).toString(16).substr(-2);
//		console.log(reshex);

		return(inputStr+reshex);
}
1180231
public static int crc16(byte[] bytes, int off, int len) {

        int crc = 0x0000;
        int end = off + len;

        for (int i = off; i < end; i++) {
            crc = doCrc(bytes[i], crc);
        }

        return crc & 0xFFFF;
    }
583747
function(inStream, block, length, crc) {
  var pos = 0;
  var lastChar = -1;
  var runLength = 0;
  while (pos < length) {
    if (runLength===4) {
      block[pos++] = 0;
      if (pos >= length) { break; }
    }
    var ch = inStream.readByte();
    if (ch === EOF) {
      break;
    }
    crc.updateCRC(ch);
    if (ch !== lastChar) {
      lastChar = ch;
      runLength = 1;
    } else {
      runLength++;
      if (runLength > 4) {
        if (runLength < 256) {
          block[pos-1]++;
          continue;
        } else {
          runLength = 1;
        }
      }
    }
    block[pos++] = ch;
  }
  return pos;
}