Question: TASK: Write C code that performs the following steps: 1 . Include qutyio.h and , and initialise the serial interface using serial _ init
TASK: Write C code that performs the following steps:
Include "qutyio.h and and initialise the serial interface
using serialinit
Create a variable "state" to store your student number in decimal.
You should use a fixedwidth integer type from the header
file.
Iterate through all the numbers from to in sequence, and for
each number, perform the following steps:
a Take the bitwise XOR of the number with the variable "state",
storing the result back into "state".
b Rotate right the bits in "state" at least one time, and until the
LSB of "state" is a zero. If there are no cleared bits in "state"
do nothing.
c Print the least significant two bytes of "state" to the serial
output as four uppercase hexadecimal digits, followed by a space.
The prefix x is not required.
d Inspect bits of "state" where bit is the LSB
If the most significant nibble of this byte, represented as a
hexadecimal digit, matches the second last digit of your student
number, represented as a decimal digit, print the word "foo" to
the serial output.
If the least significant nibble of this byte, represented as a
hexadecimal digit, matches the final digit of your student
number, represented as a decimal digit, print the word "bar" to
the serial output.
If both match, print "foobar".
e Print a newline character to the serial output.
After step your program should have printed lines to the
serial output.
Program execution should then proceed to the infinite loop without
producing any further output.
My code outputs lines, however it isnt printing them in a correct order and without foo and bar on the ends?
#include
#include "qutyio.h
#include
int mainvoid
Initialize the serial interface
serialinit;
uintt state ; placeholder
Iterate through numbers from to
for int i ; i ; i
state i;
Rotate the bits in 'state' to the right
while state &
state ;
Print the least significant two bytes of 'state'
printfX state & xFFFF;
Extract the nibbles and compare with student number digits
int msnibble state & xF;
int lsnibble state & xF;
int studentnumberdigits ;
if msnibble studentnumberdigits
printffoo;
if lsnibble studentnumberdigits
printfbar;
printf
;
END OF EXTENSION EXERCISES
DO NOT EDIT BELOW THIS LINE
while ; Loop indefinitely
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
