Subjects
PRICING
COURSES
SIGN IN
Start Free Trial
Ricardo W.
Software Developer + Electronics Enthusiast
Tutor Satisfaction Guarantee
PHP Programming
TutorMe
Question:

A user submits a number to your php script using the following HTML form, return a success message if the value is 42. For any other return an error message. <form action="script.php" method="post" > <label class="label" for="input">Please input a number: </label> <input class="input" type="number" id="input"> <input type="submit" value="Submit"> </form>

Ricardo W.
Answer:

<?php // Source for script.php // Check if input is set on POST superglobal through isset. // Should cast input to integer to be sure we are compaing numbers to numbers. // Use strict comparisson ===, to prevent undesiredly checking if 42 is a true value. // First check if variable is set, then check its value. If variable is not set then if will skip checking further conditions. if( isset($_POST['input']) && (int)$_POST['input']) === 42 ) { echo "Success, 42 is the answer to everything"; } else { echo "Error, value is not correct"; }

Computer Science (General)
TutorMe
Question:

What is an algorithm?

Ricardo W.
Answer:

An algorithm describes a solution to a problem. It is a recipe that allows someone to communicate the solution to a problem. The solution is offered in steps, which can be repeated by a person or computer to reach the solution. A formal description of the process involved in reaching a resolution to a problem. An algorithm has 5 defining characteristics: 1. Finite - Even though an algorithm can consider a large ammount of inputs, or be described by a large set of instructions, the description should be guaranteed to finish. Finishing in a million years after processing billions of steps can be uncomprehensible, but meets this characteristic. 2. Definite - Steps should be clearly defined, someone who interprets an algorithm should be left with no ambiguity to the process expected to be carried out. Normally algorithms are expressed in mathematical terms or formal computer languages to avoid ambiguity. Algorithms can be described in common language if the interpreter is expected to understand the instructions in clear manner. 3. Input values- Algorithms have a set of inputs, like numbers or a set of letters. This is data that is required to be procesed or to take decisions. Algorithms can take as few as one value or as much as required. An algorithm normally describes valid input values through a previously defined set of values from a larger universe of values (only positive numbers, values between 0 and 10, etc). Example Sum Algorithm takes two numeric values: 2 and 3 or 3 and 8. 4. Output values - An algorithm results in one or more values which are normally related to the input values through operations. Example Sum Algorithm takes 3 and 8, outputing 11. 5. Effectiveness - An algorithm should try to be as efficient as possible, solving the problem making the best use of resources. Less steps, makes the algorithm compact and easy to describe. Fast run-time, gives a soution in an optimal or reasonable time. Low memory requirements, uses available space efficiently (a person's memory, computer memory or hard drive space limit the ammount of scratch information that can be stored).

Assembly Language
TutorMe
Question:

A 8051 microcontroller needs to generate a clock signal to communicate with a legacy device. Use timers to generate a 1khz signal on P1.0. Clock speed is 12 Mhz.

Ricardo W.
Answer:

A 1khz signal requires switching the port output to the opposite value every 500 microseconds. An 8 bit timer would count for 256 cycles before setting the timer flag. A 16 bit timer would count for 65536 cycles. The 8051 will operate the timer at 1 MHZ (12Mhz/12 = 1Mhz). This means a 8 bit timer would run from 0-256 ms while a 16 bit timer 0-65536 microseconds. Since 8 bit timers are too small we should use 16 bit timers. We should set the timer to count from maximum value minus desired value. Since the 8051 operates with 8 bit instructions, two load assignments should be used one for the high part TH0 and one for the lower TL0. We require a 16 bit timer configured to run for 500us (overflow). Mode 1 sets Timer 0 to operate in 16 bits (up to 65,536 cycles). TMOD should be set as 0x01. 65536 - 500 = 65036d, 0xFE0C hexadecimal, or 1111 1110 0000 1100 binary. TH0 should be set to 0xFE. TL0 should be set to 0x0C. While waiting for the timer to overflow we can loop between a flag checking instruction, instruction will check if the timer overflow flag TF0, if not set (JNB) then the program will continue cycling. To start the timer we should set TR0 flag. We should use the CPL instruction to switch P1.0 from high to low and back. Example program: ORG 81000H ;standard starting point for 8051 MOV TMOD, #01H ; sets timer 1 to 16 bit A: MOV TH0, #0FEH; MOV TL0, #0CH; configures upper and lower parts of timer per calculations SETB TR0; starts timer B: JNB TF0, B; program will cycle in place while timer overflows CLR TR0; stop timer CLR TF0; clear timer flag (ready for next cycle) CPL P1.0; sets port 1.0 to complementary (opposite) value SJMP A; restarts END;

Send a message explaining your
needs and Ricardo will reply soon.
Contact Ricardo
Ready now? Request a lesson.
Start Session
FAQs
What is a lesson?
A lesson is virtual lesson space on our platform where you and a tutor can communicate. You'll have the option to communicate using video/audio as well as text chat. You can also upload documents, edit papers in real time and use our cutting-edge virtual whiteboard.
How do I begin a lesson?
If the tutor is currently online, you can click the "Start Session" button above. If they are offline, you can always send them a message to schedule a lesson.
Who are TutorMe tutors?
Many of our tutors are current college students or recent graduates of top-tier universities like MIT, Harvard and USC. TutorMe has thousands of top-quality tutors available to work with you.