# 
# Copyright (C) 2011-2014 Jeff Bush
# 
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
# 
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Library General Public License for more details.
# 
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA  02110-1301, USA.
# 


import sys, struct

def dump(value):
	print hex(value)
	print 'exponent', ((value >> 23) & 0xff)
	binary = ''
	sig = value & ((1 << 23) - 1)
	for x in range(23):
		if sig & (1 << (22 - x)):
			binary += '1'
		else:
			binary += '0'

	print 'significand', hex(sig), binary
	
	print struct.unpack('f', struct.pack('I', value))[0]

strval = sys.argv[1]
if strval[:2] == '0x':
	dump(int(strval[2:], 16))
elif strval.find('.') != -1:
	dump(struct.unpack('I', struct.pack('f', float(strval)))[0])
else:
	dump(int(strval))

@@ -871,21 +871,8 @@
 ff)%0A
-%09binary = ''%0A
 %09sig
@@ -902,100 +902,8 @@
  1)%0A
-%09for x in range(23):%0A%09%09if sig & (1 %3C%3C (22 - x)):%0A%09%09%09binary += '1'%0A%09%09else:%0A%09%09%09binary += '0'%0A%0A
 %09pri
@@ -937,13 +937,17 @@
  bin
-ary%0A%09
+(sig)%5B2:%5D
 %0A%09pr

make dump_fp_fields a bit more pythonic