Created
August 30, 2024 10:54
-
-
Save vadimkantorov/8f7e2d176e1b873f4ac0ed646e44594a to your computer and use it in GitHub Desktop.
Format integer string as bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://stackoverflow.com/questions/78931597/binary-integer-representation-printing-in-linux-shell?noredirect=1#comment139167055_78931597 | |
alias fmti4struct="python -c 'import sys,struct;sys.stdout.buffer.write(struct.pack(\"<I\",int(sys.argv[1])))'" | |
alias fmti4tobytes="python -c 'import sys,struct;sys.stdout.buffer.write(int(sys.argv[1]).to_bytes(4,\"little\"))'" | |
# fmt4istruct 2123 > foo.txt | |
# xxd foo.txt | |
## 00000000: 4b08 0000 K... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment