#include #include #include "qutyio.h" // Ex E3.0 // // In this week's tutorial we used some functions from a library // "qutyio.h" and from the library to output data via // the serial interface. This can be a useful tool for debugging // your programme. To use the serial interface you first need to // initialise the required hardware by calling "serial_init()"; // this only needs to be done once at the beginning of your // programme. After this, you can use the function printf() from // to output formatted strings via the serial interface. // // You will need to use printf() in few different ways in this // extension exercise: // //   printf("foo") - prints the word 'foo' to the serial output. //   printf("bar") - prints the word 'bar' to the serial output. //   printf(" ")   - prints a space to the serial output. //   printf("%02X", x) - prints the 8-bit integer 'x' to the //   serial output, formatted as two hexadecimal digits. //   printf("\n")  - prints a new line to the serial output. // // Your task is to write C code to do the following: // // 1) Include stdio.h and qutyio.h so that you can access the //    functions required to write to the serial interface. // 2) Initialise the qutyio serial inteface by calling serial_init(). // 3) Create a variable "state" to store your student number. You //    should interpret your student number as a decimal number. Use //    the smallest standard unsigned integer type in which your student //    number will fit. (you will need to include the stdint header). //    e.g. the student number 10000012 would represent the number //    ten million and twelve. // 4) Iterate through all the numbers from 0 to 255 in sequence. //    For each number in the sequence 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 the four hexadecimal digits and a space. No prefix is //       required. //    d) Inspect the bits 11-4 of "state" (where bit 0 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 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 decimal digit, print the //       word "bar" to the serial output. If both match, print "foobar". //    e) Print a newline character to the serial output. // 5) Based on step 4 above, your programme should have printed 256 //    lines to the serial output. After completion of step 4 programme //    execution should proceed to the infinite loop without producing //    any further output. // // Examples: //   Assume for all examples below the student number is n12345678 //   //   Assume that after step 4b "state" holds the value 0x11223344 //     The programme should print the line: 3344 // //   Assume that after step 4b "state" holds the value 0x34567728 //     The programme should print the line: 7728 foo   // //   Assume that after step 4b "state" holds the value 0x11111780 //     The programme should print the line: 1780 foobar     int main(void) { // Write your code for Ex E3.0 below this line. // You will also need to add some preprocessor directives; // these would typically go at the top of the file.     // Initialise serial interface     serial_init();     // Create variable to store student number     uint32_t student_num = 11233184;     uint8_t state = student_num;     // Iterate through numbers from 0 to 255     for (uint8_t i = 0; i <= 255; i++) {         // Perform XOR with state         state ^= i;         // Rotate right until LSB is 0         while ((state & 1) == 1) {             state >>= 1;             state |= (state & 0x80) ? 0x80 : 0;         }         // Print least significant two bytes of state in hex format         printf("%02X%02X ", state & 0xFF, (state >> 8) & 0xFF);         // Check nibbles for 'foo' or 'bar'         uint8_t nibble1 = (state >> 4) & 0xF;         uint8_t nibble2 = state & 0xF;         if (nibble1 == (student_num % 100 / 10)) {             printf("foo ");         }         if (nibble2 == student_num % 10) {             printf("bar");         }         if (nibble1 == (student_num % 100 / 10) && nibble2 == (student_num % 10)) {             printf("foobar");         }                 printf("\n");     } // END OF EXTENSION03 EXERCISES // // DO NOT EDIT BELOW THIS LINE //         while(1) {         // Loop forever     }         return 0; } Test failed on line 0. Expected: B3D0 Found: A000

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
#include <stdio.h>
#include <stdint.h>
#include "qutyio.h"

// Ex E3.0
//
// In this week's tutorial we used some functions from a library
// "qutyio.h" and from the <stdio.h> library to output data via
// the serial interface. This can be a useful tool for debugging
// your programme. To use the serial interface you first need to
// initialise the required hardware by calling "serial_init()";
// this only needs to be done once at the beginning of your
// programme. After this, you can use the function printf() from
// <stdio.h> to output formatted strings via the serial interface.
//
// You will need to use printf() in few different ways in this
// extension exercise:
//
//   printf("foo") - prints the word 'foo' to the serial output.
//   printf("bar") - prints the word 'bar' to the serial output.
//   printf(" ")   - prints a space to the serial output.
//   printf("%02X", x) - prints the 8-bit integer 'x' to the
//   serial output, formatted as two hexadecimal digits.
//   printf("\n")  - prints a new line to the serial output.
//
// Your task is to write C code to do the following:
//
// 1) Include stdio.h and qutyio.h so that you can access the
//    functions required to write to the serial interface.
// 2) Initialise the qutyio serial inteface by calling serial_init().
// 3) Create a variable "state" to store your student number. You
//    should interpret your student number as a decimal number. Use
//    the smallest standard unsigned integer type in which your student
//    number will fit. (you will need to include the stdint header).
//    e.g. the student number 10000012 would represent the number
//    ten million and twelve.
// 4) Iterate through all the numbers from 0 to 255 in sequence.
//    For each number in the sequence 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 the four hexadecimal digits and a space. No prefix is
//       required.
//    d) Inspect the bits 11-4 of "state" (where bit 0 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 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 decimal digit, print the
//       word "bar" to the serial output. If both match, print "foobar".
//    e) Print a newline character to the serial output.
// 5) Based on step 4 above, your programme should have printed 256
//    lines to the serial output. After completion of step 4 programme
//    execution should proceed to the infinite loop without producing
//    any further output.
//
// Examples:
//   Assume for all examples below the student number is n12345678
//  
//   Assume that after step 4b "state" holds the value 0x11223344
//     The programme should print the line: 3344
//
//   Assume that after step 4b "state" holds the value 0x34567728
//     The programme should print the line: 7728 foo  
//
//   Assume that after step 4b "state" holds the value 0x11111780
//     The programme should print the line: 1780 foobar    

int main(void) {
// Write your code for Ex E3.0 below this line.
// You will also need to add some preprocessor directives;
// these would typically go at the top of the file.
    // Initialise serial interface
    serial_init();

    // Create variable to store student number
    uint32_t student_num = 11233184;
    uint8_t state = student_num;

    // Iterate through numbers from 0 to 255
    for (uint8_t i = 0; i <= 255; i++) {
        // Perform XOR with state
        state ^= i;

        // Rotate right until LSB is 0
        while ((state & 1) == 1) {
            state >>= 1;
            state |= (state & 0x80) ? 0x80 : 0;
        }

        // Print least significant two bytes of state in hex format
        printf("%02X%02X ", state & 0xFF, (state >> 8) & 0xFF);

        // Check nibbles for 'foo' or 'bar'
        uint8_t nibble1 = (state >> 4) & 0xF;
        uint8_t nibble2 = state & 0xF;

        if (nibble1 == (student_num % 100 / 10)) {
            printf("foo ");
        }

        if (nibble2 == student_num % 10) {
            printf("bar");
        }

        if (nibble1 == (student_num % 100 / 10) && nibble2 == (student_num % 10)) {
            printf("foobar");
        }
       

        printf("\n");
    }

// END OF EXTENSION03 EXERCISES //
// DO NOT EDIT BELOW THIS LINE //
   
    while(1) {
        // Loop forever
    }
   
    return 0;
}

Test failed on line 0. Expected: B3D0 Found: A000 
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

It still have this error
Test failed on line 0. Expected: B3D0 Found: A000 

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Concept of memory addresses in pointers
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education