Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java Program - Hex to Binary to Decimal plus ram chip location Text file: Errors

ID: 3755508 • Letter: J

Question

 Java Program - Hex to Binary to Decimal plus ram chip location  Text file: ErrorsRam.txt      
 032DAE01AD 100CDAEFFA 29A0EDF301 196CDAEFC0 33CDAEFFAD 21A00D0000 F3ABCDEFAB 3ABCDEFABC
       Each record in this file represents the location of an error found in RAM        3) Assume you have a computer with 32 gigs of RAM, each 4 gigs in a      different memory chip, therefore you have 8 (eight) 4 gigs RAM chips.                                     ---------- decimal address ----------   GIGs     RAM chip 0 contain addresses:              0 -  34,359,738,368 bits =    4     RAM chip 1 contain addresses: 34,359,738,369 -  68,719,476,738 bits =    8     RAM chip 2 contain addresses: 68,719,476,739 - 103,079,215,108 bits =   12     RAM chip 3 contain addresses:103,079,215,109 - 137,438,953,478 bits =   16     RAM chip 4 contain addresses:137,438,953,479 - 171,798,691,848 bits =   20     RAM chip 5 contain addresses:171,798,691,849 - 206,158,430,218 bits =   24     RAM chip 6 contain addresses:206,158,430,219 - 240,518,168,588 bits =   28      RAM chip 7 contain addresses:240,518,168,589 - 274,877,906,958 bits =   32                         This program will do the following:  5) Open the text file  ( named on question 2 above )   6) Read each record, which is the location of an error in RAM, in hex  7) Convert that hex value to binary   8) Convert the binary value to decimal value  9) Print the RAM chip number where the error is located for each record     as follows:             Error                                                  Found at        hex number  =  binary number  =  decimal number  =  chip number                      note: Location addresses for RAM chips are decimal              *** DO NOT CHANGE THE FILE NAME         *** MAKE SURE THE FILE IS IN THE SAME FOLDER AS YOUR JAVA PROGRAM        *** CREATE YOUR OWN METHODS THAT WILL CONVERT            HEX TO BINARY AND BINARY TO DECIMAL        *** DO NOT USE JAVA'S AUTOMATIC CONVERSION METHODS          *** DO NOT USE JAVA'S PARSE COMMANDS         *** USE System.out.printf commands ONLY to print any data

Explanation / Answer

ANSWER:

Each record in this file represents the location of an error found in RAM.

package pgm2;

import java.io.BufferedReader;

import java.io.FileNotFoundException;

import java.io.FileReader;

import java.io.IOException;

public class RobinsonM_OSpgm2 {

public static void main(String[] args) throws FileNotFoundException, IOException {

RobinsonM_OSpgm2 ob=new RobinsonM_OSpgm2();

String hex,bin,st;

long dec;

BufferedReader br=new BufferedReader(new FileReader("output.txt"));

while((st=br.readLine())!=null){

hex=st;

bin=ob.hexToBinary(hex);

dec=(long)ob.binToDecimal(bin);

System.out.println("RAM chip number where the error is located: ");

System.out.println(hex+" = "+bin+" = "+dec+" ="+ob.chipNumber(dec));

}

}

public String hexToBinary(String str){

String bin="";

for(int i=0;i<str.length();i++){

char ch=str.charAt(i);

switch(ch){

case '0':{

bin=bin+"0000";

break;

}

case '1':{

bin=bin+"0001";

break;

}

case '2':{

bin=bin+"0010";

break;

}

case '3':{

bin=bin+"0011";

break;

}

case '4':{

bin=bin+"0100";

break;

}

case '5':{

bin=bin+"0101";

break;

}

case '6':{

bin=bin+"0110";

break;

}

case '7':{

bin=bin+"0111";

break;

}

case '8':{

bin=bin+"1000";

break;

}

case '9':{

bin=bin+"1001";

break;

}

case 'A':{

bin=bin+"1010";

break;

}

case 'B':{

bin=bin+"1011";

break;

}

case 'C':{

bin=bin+"1100";

break;

}

case 'D':{

bin=bin+"1101";

break;

}

case 'E':{

bin=bin+"1110";

break;

}

case 'F':{

bin=bin+"1111";

break;

}

default:{

System.err.println("Invalid hex value "+ch);;

}

}

}

return bin;

}

public long binToDecimal(String str){

long num=0;

for(int i=0;i<str.length();i++){

num=(long) (num+((Integer.parseInt(""+str.charAt(i)))*Math.pow(2, i)));

}

return num;

}

public int chipNumber(double num){

int chip=0;

if(num>=0 && num<=34359738368l){

chip=0;

}

else if(num>=34359738369l && num<= 68719476738l){

chip=1;

}

else if(num>=68719476739l && num<= 103079215108l){

chip=2;

}

else if(num>=103079215109l && num<= 137438953478l){

chip=3;

}

else if(num>=137438953479l && num<= 171798691848l){

chip=4;

}

else if(num>=171798691849l && num<= 206158430218l){

chip=5;

}

else if(num>=206158430219l && num<= 240518168588l){

chip=6;

}

else{

chip=8;

}

return chip;

}

}

-------------------------------------------

output

RAM chip number where the error is located:
3ABCDEFABC = 0011101010111100110111101111101010111100 = 263594917212 =7
RAM chip number where the error is located:
21A00D0000 = 0010000110100000000011010000000000000000 = 11535748 =0
RAM chip number where the error is located:
100CDAEFFA = 0001000000001100110110101110111111111010 = 412171841544 =7
RAM chip number where the error is located:
29A0EDF301 = 0010100110100000111011011111001100000001 = 553240692116 =7
RAM chip number where the error is located:
F3ABCDEFAB = 1111001110101011110011011110111110101011 = 918983792079 =7
RAM chip number where the error is located:
33CDAEFFAD = 0011001111001101101011101111111110101101 = 781674984396 =7
RAM chip number where the error is located:
196CDAEFC0 = 0001100101101100110110101110111111000000 = 17034851992 =0
RAM chip number where the error is located:
032DAE01AD = 0000001100101101101011100000000110101101 = 779544278208 =7

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote