In your Centos7 VM (virtual machine), using terminal mode ONLY, do the following
ID: 3755406 • Letter: I
Question
In your Centos7 VM (virtual machine), using terminal mode ONLY, do the following: 1) Create a folder named pgm2 2) In this folder (pgm2) place the text file located at: http://users.cis.fiu.edu/~mrobi002/databases/RAMerrors8x4b 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 I used this link to do the calculations: http://www.matisse.net/bitcalc/?input_amount=274%2C877%2C906%2C958&input_units=bits¬ation=legacy 4) In the same folder (pgm2), in terminal mode, using the VI editor, create a Java program named: your lastName, First letter of your first name, _OS, pgm2, java example: robinsonM_OSpgm2.java 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:
Centos7VM Using terminal mode
import java.util.Scanner;
import java.io.File;
import java.io.IOException;
import java.math.BigInteger;
public class robinsonM_OSpgm2
{
public static String decoutput="";
public static void hexTobinary(String s)
{
String digits = "0123456789ABCDEF";
String binaryNum="";
String binnum[] = {"0000","0001","0010","0011","0100","0101","0110","0111","1000","1001","1010","1011","1100","1101","1110","1111"};
System.out.print("Binary Value : ");
for (int i = 0; i < s.length(); i++)
{
char c = s.charAt(i);
int d = digits.indexOf(c);
System.out.print(binnum[d] +" ");
decoutput=decoutput.concat(binnum[d]);
}
System.out.print(" ");
}
public static void BinaryToDecimal(String binaryNumber)
{
long p=0;
int d;
int len= binaryNumber.length();
for(int i=0;i<len;i++)
{
char c=binaryNumber.charAt(i);
d=Character.getNumericValue(c);
p= (p * 2) + d;
}
System.out.println("Decimal value : " + p);
RamChip(p);
}
public static void RamChip(long Adress)
{
if(Adress >= 0 && Adress <= 8589934584L)
{System.out.println("Error found in RAM chip 0 ");}
else if(Adress >= 8589934585L && Adress <= 17179869184L)
System.out.println("Error found in RAM chip 1 ");
else if(Adress >= 17179869185L && Adress <= 25769803768L)
System.out.println("Error found in RAM chip 2 ");
else if(Adress >= 25769803769L && Adress <= 34359738368L)
System.out.println("Error found in RAM chip 3 ");
else
System.out.println("No error Found");
}
public static void main(String args[])
{
String fileName = "pgm2.txt";
String hexvalue;
try (Scanner scanner = new Scanner(new File(fileName))) {
while (scanner.hasNext()){
hexvalue=scanner.nextLine();
System.out.println(" Hex Value : " + hexvalue);
hexTobinary(hexvalue.trim());
BinaryToDecimal(decoutput);
decoutput="";
}
} catch (IOException e) {
e.printStackTrace();
}
}
}