Data Length and Base Conversion
As a bitcoin programmer, it is often useful to know the length of some data or convert to a different base. The file base_converter.js provides a very simple tool box to do just that.
Base Conversion
$ npm run bin2dec 101010
42
$ npm run bin2hex 101010
2a
$ npm run dec2bin 42
101010
$ npm run dec2hex 42
2a
$ npm run hex2bin 2a
101010
$ npm run hex2dec 2a
42
Data Length
Let’s calculate the byte length of alice_1 pubKeyHash.
lenBytesHex
takes a hex string and returns the byte length expressed in hexadecimal
$ npm run lenBytesHex fb8820f35effa054399540b8ca86040d8ddaa4d5
14
If we want to push this pubKeyHash onto the stack we will use a PUSHBYTES_14, which is actually 20 bytes in decimal.
lenBytesDec
takes a hex string and returns the byte length expressed in decimal
$ npm run lenBytesDec fb8820f35effa054399540b8ca86040d8ddaa4d5
20