python - recasting floats to ieee754 representation in gdb -
hi i'm playing following, i'd convert between ieee754 representation , decimal float in linux shell. way i've found is:
gdb --batch -ex "print/x (float *) ( (float) 1234.567 )" gdb --batch -ex "print/f (float *) 0x449a5225"
but doesn't work double , long double ("invalid cast"), gdb truncates values greater 32bit, double , long double.
is there gdb expert help?
i've found own solution, python:
# python -c 'import struct; print "%#x" % struct.unpack("i", struct.pack("f", 1234.567))' 0x449a5225 # python -c 'import struct; print "%#x" % struct.unpack("q", struct.pack("d", 1234.567))' 0x40934a449ba5e354 # python -c 'import struct; print "%f" % struct.unpack("d", struct.pack("q", 0x4094b2449ba5e354))' 1324.567000 # python -c 'import struct; print "%f" % struct.unpack("f", struct.pack("i", 0x449a5225 ))' 1234.566895
Comments
Post a Comment