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

Convert each letter of your first name to different representations including de

ID: 3751705 • Letter: C

Question

Convert each letter of your first name to different representations including decimal, binary, hexadecimal, and octal. You will also write those information into a text file. In this assignment, you will write PHP code for following functionalities:

1. Use $name to store your first name and store each letter of your name to an array called $nameLetterArray by calling the str_split method (search PHP manual for details).

2. Create a file called “result.txt” and write a message to the file to show how your name is spelled. For example, if your name is John, the message should look like: John is spelled as J o h n Do not write this message manually. Use loop to go through the $nameLetterArray to write each letter. After this message, insert a new line. You can use PHP_EOL for that.

3. In computer, there is a corresponding numeric value for each character. For example, Character ‘J’ is 74 in decimal system, which is 1001010 in binary, 4A in hexadecimal, and 112 in octal.. In order to get that decimal value for each character, use ord() function in PHP and use sprintf() function to convert it to other representations. (Search PHP manual for details of ord()).

4. Use loop to write the following sentences to the file. For each letter of your name, show each letter’s representation in the form of decimal, binary, hexadecimal, and octal, respectively. Again, if your name is John, you will write the following sentences to the file: John is spelled as: J o h n Decimal representation of J is 74 Binary representation of J is 1001010 Hexadecimal representation of J is 4A Octal representation of J is 112 Decimal representation of o is 111 Binary representation of o is 1101111 Hexadecimal representation of o is 6F Octal representation of o is 157 Decimal representation of h is 104 Binary representation of h is 1101000 Hexadecimal representation of h is 68 Octal representation of h is 150 Decimal representation of n is 110 Binary representation of n is 1101110 Hexadecimal representation of n is 6E Octal representation of n is 156

5. At the end of the file, print a timestamp. Set the time zone to central time and print the following sentence. Make sure your date output is in the EXACTLY same format as this sample one with comma after day of week, without suffix for day of month, and hour in military time format, and without time specifier of am/pm: This file was updated at Friday, September 22, 2018 - 17:38

Please make sure you specify “result.txt” as the name of the file to write to in your code.

Explanation / Answer

<?php

$name="Tarun"

$nameLetterArray = str_split($name);

$nameis=$name," is spelled as ";

$len=strlen($name);

$myfile=fopen("result.txt","w"); or die("File couldn't be opened!");

fwrite($myfile, $nameis);

for($x=0;$x<$len;$x++){

fwrite($myfile, $nameLetterArray[$x]);

}

fwrite($myfile, PHP_EOL);

for($x=0;$x<$len;$x++){

fwrite($myfile, "Decimal representation of ");

fwrite($myfile,$nameLetterArray[$x]);

fwrite($myfile," is ");

fwrite($myfile,ord($nameLetterArray[$x]));

fwrite($myfile, "Binary representation of ");

fwrite($myfile,$nameLetterArray[$x]);

fwrite($myfile," is ");

fwrite($myfile,decbin($nameLetterArray[$x]));

fwrite($myfile, "Hexadecimal representation of ");

fwrite($myfile,$nameLetterArray[$x]);

fwrite($myfile," is ");

fwrite($myfile,dechex($nameLetterArray[$x]));

fwrite($myfile, "Octal representation of ");

fwrite($myfile,$nameLetterArray[$x]);

fwrite($myfile," is ");

fwrite($myfile,decoct($nameLetterArray[$x]));

fwrite($myfile, PHP_EOL);

}

fwrite($myfile, date("l"));
fwrite($myfile, ", ");
fwrite($myfile, date("n"));
fwrite($myfile, date("d"));
fwrite($myfile, ", ");
fwrite($myfile, date("Y"));
fwrite($myfile, " - ");
fwrite($myfile, date("H"));
fwrite($myfile, ":");
fwrite($myfile, date("i"));

fclose($myfile);

?>

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