mirror of
https://github.com/ChristopherA/Learning-Bitcoin-from-the-Command-Line.git
synced 2025-06-08 08:26:17 +00:00
Update 8_1_Understanding_the_Foundation_of_P2SH.md
This commit is contained in:
parent
13d879ea52
commit
2e3025eeb5
@ -92,7 +92,12 @@ $ hex=$(printf '%08x\n' $integer | sed 's/^\(00\)*//')
|
|||||||
$ echo $hex
|
$ echo $hex
|
||||||
5c2a7b9f
|
5c2a7b9f
|
||||||
```
|
```
|
||||||
Third, you need to translate the hex from big-endian (least significant byte last) to little-endian (least significant byte first). You can do this with the `tac` command (or by hand if you prefer):
|
Third, you need to add a byte of `00` if the top digit is "8" or greater, so that it's not interpretted as a negative number.
|
||||||
|
```
|
||||||
|
$ hexfirst=$(echo $hex | cut -c1)
|
||||||
|
$ [[ 0x$hexfirst -gt 0x7 ]] && hex="00"$hex
|
||||||
|
```
|
||||||
|
Fourth, you need to translate the hex from big-endian (least significant byte last) to little-endian (least significant byte first). You can do this with the `tac` command (or by hand if you prefer):
|
||||||
```
|
```
|
||||||
$ lehex=$(echo $hex | tac -rs .. | echo "$(tr -d '\n')")
|
$ lehex=$(echo $hex | tac -rs .. | echo "$(tr -d '\n')")
|
||||||
$ echo $lehex
|
$ echo $lehex
|
||||||
@ -206,7 +211,7 @@ _What is the power of P2SH?_ You already know the power of Bitcoin Script, which
|
|||||||
|
|
||||||
## Appendix: The Integer Conversion Script
|
## Appendix: The Integer Conversion Script
|
||||||
|
|
||||||
The following script collects the collect methodology for changing an integer to -2147483647 and 2147483647 to a little-endian signed-magnitude representation:
|
The following script collects the complete methodology for changing an integer between -2147483647 and 2147483647 to a little-endian signed-magnitude representation:
|
||||||
```
|
```
|
||||||
file: integer2lehex.sh
|
file: integer2lehex.sh
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
@ -232,8 +237,11 @@ else
|
|||||||
negative=0;
|
negative=0;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
hex=$(printf '%08x\n' $integer | sed 's/^\(00\)*//');
|
hex=$(printf '%08x\n' $integer | sed 's/^\(00\)*//');
|
||||||
|
|
||||||
|
hexfirst=$(echo $hex | cut -c1)
|
||||||
|
[[ 0x$hexfirst -gt 0x7 ]] && hex="00"$hex
|
||||||
|
|
||||||
lehex=$(echo $hex | tac -rs .. | echo "$(tr -d '\n')");
|
lehex=$(echo $hex | tac -rs .. | echo "$(tr -d '\n')");
|
||||||
|
|
||||||
if [ "$negative" -eq "1" ];
|
if [ "$negative" -eq "1" ];
|
||||||
@ -241,7 +249,6 @@ then
|
|||||||
lehex=$(printf '%x\n' $((0x$lehex | 0x80)))
|
lehex=$(printf '%x\n' $((0x$lehex | 0x80)))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
size=$(echo -n $lehex | wc -c | awk '{print $1/2}');
|
size=$(echo -n $lehex | wc -c | awk '{print $1/2}');
|
||||||
hexcodeprefix=$(printf '%02x\n' $size);
|
hexcodeprefix=$(printf '%02x\n' $size);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user