Skip to content

Instantly share code, notes, and snippets.

@vadimkantorov
Created August 30, 2024 10:54
Show Gist options
  • Save vadimkantorov/8f7e2d176e1b873f4ac0ed646e44594a to your computer and use it in GitHub Desktop.
Save vadimkantorov/8f7e2d176e1b873f4ac0ed646e44594a to your computer and use it in GitHub Desktop.
Format integer string as bytes
# 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