I recently had an assignment in class where we had to convert an IEEE 754 double precision floating point from hexadecimal to decimal by hand showing all work and after quite a bit of searching was unable to find any fully fleshed out examples. Making use of this resource which explains how to convert from decimal format to IEEE 754 format I reversed parts of the process and added in other bits and pieces from stackoverflow to get the answer. As I am somewhat lazy I am just going to attach an image of the work done by hand that should be rather easy to follow.

One part of the conversion is calculating the Mantissa which is an error prone process so instead of calculating it all by hand I wrote a simple Java program to accomplish the task.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
import java.util.ArrayList; import java.util.List; public class Mantissa { public static double computeMantissa(Integer[] mantissa) { double total = 0; double denominator = 2; for (int bit : mantissa) { total += bit / denominator; denominator *= 2; } return total; } public static void main(String[] args) { String mantString = "0010 1001 1100 0010 1000 1111 0101 1100 0010 " + "1000 1111 0101 1100"; List<Integer> mantList = new ArrayList<>(); for (int i = 0; i < mantString.length(); i++) { Character c = mantString.charAt(i); if (c == '0' || c == '1') { mantList.add(Character.getNumericValue(c)); } } if (mantList.size() != 52) { System.out.println("Invalid Mantissa"); return; } Integer[] mantArray = mantList.toArray(new Integer[mantList.size()]); double result = computeMantissa(mantArray); System.out.println("Result: " + result); } } |