hi all,

I don 't have good enough planning documentation at my finger tips to get this exactly right. I have an input file and I'm reading it line by line. All lines are either hex or bin numbers. I'm taking them in as a string and I'm doing the math on them by using ints and doubles. They will eventually be printed out in a table using printf(). I'm getting lost in *when* to use and int, when to use a double, does it really matter, and then some. Can someone help me out here? There is only a little bit of this code that is relevant, and I've blocked it out with width-wide comments. thanks!

where it says "loss of precision is occurring here, that's where I've stopped because I seem to just be getting deeper and deeper into this issue. Yes this is a homework assignment and unfortunately the instructor simply wants people to conditionalize and case-statement *everything* out, which of course completely defeats the purpose of developing the mathematical mindset that professionals are supposed to have. Can you guys give me a boost here on this? Hopefully what I'm trying to do is self evident here. The case statements will be written out for all base 16 numbers, but just did one otherwise code would be too long.Code:`/* The following equations are those that are used in this program for conversions between number bases...`

*

* ANY to DECIMAL: (bit value (or byte value) * (source base ^ bit or byte position)).

* DECIMAL to HEX: Decimal value / 16 => remainder appended as new MSB. Do until Decimal value = 0.

* DECIMAL to BINARY: Decimal value / 2 => remainder appended as new MSB. Do until Decimal value = 0.

*

*/

import java.io.*;

import java.util.*;

import java.lang.String;

import java.lang.Math;

class program_3

{

public static void main(String args[])

{

//COUNTER VARIABLES

int ctr=0;

int ctrRev=0;

//INPUT VARIABLES

String valInput="";

int valLength=0;

//CONVERSION VARIABLES

String valBin="";

String valHex="";

String valDec="";

double valDecDBL = 0;

int baseSource=0;

final double base2=2;

final double base10=10;

final double base16=16;

double bitPos=0;

int bytePos=0;

double valQuotient=0;

int valRemainder=0;

char bitVal;

double bitValDBL = 0;

char byteVal;

boolean isBinary;

FileInputStream fs = new FileInputStream("c:/input.txt");

Scanner sc = new Scanner(fs);

//print table headings.

System.out.printf("%20s %20s %20s\n", "Binary", "Decimal", "Hexidecimal");

While (sc.hasNextLine())

{

valInput = sc.nextLine();

valLength = valInput.length();

//check if binary or hex, use string length = 4 as criteria.

if (valLength != 4)

{

isBinary = true;

valBin = valInput; valDec = ""; valHex = "";

}

Else

{

isBinary = false;

valHex = valInput; valDec = ""; valBin = "";

}

if (isBinary)

{

//BINARY TO DECIMAL => (bit value (or byte value) * (source base ^ bit or byte position))

valDecDBL = 0;

ctrRev = 0;

for (ctr = valLength - 1; ctr >= 0; ctr--)

{

bitVal = valInput.charAt(ctrRev);

bitPos = ctr;

if (bitVal == '1')

{

bitValDBL = 1;

valDecDBL = valDecDBL + (bitValDBL * (Math.pow(base2, bitPos)));

}

ctrRev++;

}

//DECIMAL TO HEX => (Decimal value / 16) => remainder appended as new MSB. Do until Decimal value = 0.

valHex = "";

while (valDecDBL != 0)

{

valQuotient = Math.floor(valDecDBL / base16);

valRemainder = valDecDBL % base16; //loss of precision is occurring here...

Switch (valRemainder)

{

case 15: valHex = "15";

//etc, etc...

}

}

}

}

}

}

thanks!