I am writing a program to
1. read a text file that contains 8 lines of hexadecimals
2. convert the lines to binary, and then decimal
3. Output to attached image
So far this is what I have:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ramerros;
import java.io.File;
import java.io.FileNotFoundException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Scanner;
import static javax.swing.text.html.HTML.Tag.I;
/**
*
* @author Jose
*/
public class Ramerros {
public static void main (String[] args) throws FileNotFoundException
{
Scanner textDataFile = new Scanner(new File("/Desktop/RAMerrors2.txt"));
while(textDataFile.hasNextLine()){
ArrayList<String> textData = new ArrayList<String>();
final String storedValue = textDataFile.nextLine();
String line = storedValue;
Scanner scanner = new Scanner(line);
scanner.useDelimiter(",");
while(scanner.hasNext()){
textData.add(scanner.next());
}
BigInteger bigint = new BigInteger(storedValue, 16);
final String bin = bigint.toString(2);
BigInteger bigInt = new BigInteger(bin,2);
BigDecimal bigDec = new BigDecimal(bigInt);
System.out.println(storedValue);
System.out.println(bin);
System.out.println(bigDec);
}
Currently this is my output:
ABCDEFABC 101010111100110111101111101010111100 46118402748 1FFFFFFFF 111111111111111111111111111111111 8589934591 1A00D0000 110100000000011010000000000000000 6980173824 13A0A1EFF 100111010000010100001111011111111 5268709119 7A0EDF301 11110100000111011011111001100000001 32764719873 1A2329AFF 110100010001100101001101011111111 7016192767 3CDAEFFAD 1111001101101011101111111110101101 16335699885 16697D0FF 101100110100101111101000011111111 6016192767
I am trying to include 1 function that has all conversions and I'm able to return 1 value, for example is I set the return variable to storedValue, and I just have to simply run System.out.println(storedValue) to achieve the same output as my previous code.
I then need to write the variable into an array to properly display as my output.
Any help pushing me in the right direction will help...
Thanks guys, and this is my first post, glad to be here!!

New Topic/Question
Reply


MultiQuote








|