Help with output 32bit signed integer

How do I store a number as a 32-bit little-endian Signed Integer?

Do you have a big Endian 32-bit integer you want to convert?
There are ways to do this, but they depend on what you are trying to do. I could guess, but to give you a good answer requires knowing what you are doing and what UNIX tools you have access to.
What UNIX: [answer here]
What Shell: [answer here]
What I am trying to do: [answer here]

Short answer -
you can write a C macro
You can use dd conv=swab to convert binary files

Longhand using OSX 10.13.6, default bash terminal:

Last login: Fri Oct  5 18:30:55 on ttys000
AMIGA:amiga~> pos32=$( printf "%x\n" "$(( 1234567890 & 0xFFFFFFFF ))" )
AMIGA:amiga~> neg32=$( printf "%x\n" "$(( -1234567890 & 0xFFFFFFFF ))" )
AMIGA:amiga~> echo "$pos32"
499602d2
AMIGA:amiga~> echo "$neg32"
b669fd2e
AMIGA:amiga~> littleend=$( printf "%b\n" "${pos32:6:2}${pos32:4:2}${pos32:2:2}${pos32:0:2}" )
AMIGA:amiga~> echo "$littleend"
d2029649
AMIGA:amiga~> littleend=$( printf "%b\n" "${neg32:6:2}${neg32:4:2}${neg32:2:2}${neg32:0:2}" )
AMIGA:amiga~> echo "$littleend"
2efd69b6
AMIGA:amiga~> _
1 Like