Generally speaking, the FunC code op::increase = "op::increase"c
first converts this into a uint
(unsigned integer), since in TVM (Turing Virtual Machine), communication is done only in unsigned integers to distinguish the unlimited
functions that you build.
On the other hand, the uint
can be converted into hex
code to save space when storing it in a Smart Contract.
**Here's an example in TypeScript to finalize the op-code into uint and hex data. It uses the CRC32 method to decompress this OP-code information.
**
Code:
const POLYNOMIAL = -306674912;
let crc32_table: Int32Array | undefined = undefined;
export function crc32(str: string, crc = 0xFFFFFFFF) {
let bytes = Buffer.from(str);
if (crc32_table === undefined) {
calcTable();
}
for (let i = 0; i < bytes.length; ++i)
crc = crc32_table![(crc ^ bytes[i]) & 0xff] ^ (crc >>> 8);
return (crc ^ -1) >>> 0;
}
function calcTable() {
crc32_table = new Int32Array(256);
for (let i = 0; i < 256; i++) {
let r = i;
for (let bit = 8; bit > 0; --bit)
r = ((r & 1) ? ((r >>> 1) ^ POLYNOMIAL) : (r >>> 1));
crc32_table[i] = r;
}
}
Once we call the function crc32("deposit")
, we can obtain the value 0xb04a29cf
in practice.
For more information about the CRC32 method, you can refer to the following links: