Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in C language include #include #include char str_c[30], str_v[30]; void convert_uint16_number_to_binary_str(uint16_t num, char *cPtr); void print_str_compact(uint16_t num, char *cPtr); void print_str_verbose(uint16_t num, char *cPtr_c, char

image text in transcribed in C language
include
#include
#include
char str_c[30], str_v[30];
void convert_uint16_number_to_binary_str(uint16_t num, char *cPtr);
void print_str_compact(uint16_t num, char *cPtr);
void print_str_verbose(uint16_t num, char *cPtr_c, char *cPtr_v);
int main(void) {
uint16_t test_num[] = {0x1234, 0x5678, 0x9ABC, 0xDEF0};
int N = sizeof(test_num) / sizeof(test_num[0]);
printf("Testing the printout of binary numbers: ");
for (int i = 0; i
printf("Compact display for 0x%X is ", test_num[i]);
print_str_compact(test_num[i], str_c);
printf(" ");
printf("Verbose display for 0x%X is ", test_num[i]);
print_str_verbose(test_num[i], str_c, str_v);
printf(" ");
}
while (1);
}
void convert_uint16_number_to_binary_str(uint16_t num, char *cPtr) {
}
void print_str_compact(uint16_t num, char *cPtr) {
}
void print_str_verbose(uint16_t num, char *cPtr_c, char *cPtr_v) {
}
Here is a real problem we want to solve. The standard printf function in C cannot be used to print an integer in the
binary form. In this workshop, we write C functions that can be used to print an uint16_t integer in two different binary
forms, the compact one and the verbose one, as detailed later.
Note that we don't need to use the Discovery Board for this workshop. The simulator in Keil is used for simplicity.
The basic idea is to convert an unsigned integer into a string of zeros and ones that represent the binary form of this
number and then print out this string. For the conversion, please use the method we discussed in Section 2.1.2 of letr030-
050_into_2_embedded_C.pdf.
Use the following code snippet as a starting point:
code has been added, above
Below are the programming requirements of the assignment.
(40 points) Write a function named convert_uint16_number_to_binary_str which converts a uint16 num to a string
of binary bits and save the results to cPtr.
(10 points) Write a function named print_str_compact which can be used to print the compact form of the binary
string. Note that you need to call convert_uint16_number_to_binary_str in this function to perform the
conversion and then print. Note that you cannot print the newline since we may join strings in the same line.
This is the reason why we have used printf( ); after calling this function.
(40 points) Write a function named print_str_verbose which can be used to print the results in the verbose form.
In this function, you need to call convert_uint16_number_to_binary_str as well. You then need to build cPtr_v
from cPtr_c. Finally, you print out cPtr_v in a manner similar to print_str_compact.
You may want to perform this project using the following steps:
First, get started by running an existing example project, such as the one from Workshop 1 or Lab 1. Move to the
next step when the example project works.
Then, you need to copy the code snippet given above and try to compile it. It should compile without any error.
You can then run the project and see the printout results. Of course, you don't have the correct results yet.
Next, you need to program the project step by step. Always program a couple of lines and then compile and debug.
For this project, we mainly use printf to see the results. In the labs, we will play with true debug skills.
image text in transcribed
. (40 points) Write a function named convert_uint16_number_to_binary_str which converts a uint16 num to a string of binary bits and save the results to cPtr. (10 points) Write a function named print_str_compact which can be used to print the compact form of the binary string. Note that you need to call convert_uint16_number_to_binary_str in this function to perform the conversion and then print. Note that you cannot print the newline " " since we may join strings in the same line. This is the reason why we have used "printf(" ");" after calling this function (40 points) Write a function named print_str_verbose which can be used to print the results in the verbose form. In this function, you need to call convert_uint16_number_to_binary_str as well. You then need to build cPtr_v from cPtr c. Finally, you print out cPtr v in a manner similar to print str compact. The running result should be similar to Debug (print) Viewer Testing the printout of binary numbers: Compact display for Ox1234 is 0001001000110100 Verbose display for Ox1234 is Ob0001_0010_0011_0100 Compact display for Ox5678 is 0101011001111000 Verbose display for Ox5678 is Ob0101_0110_0111_1000 Compact display for 0x9ABC is 1001101010111100 Verbose display for Ox9ABC is 061001_1010_1011_1100 Compact display for 0xDEFO is 1101111011110000 Verbose display for OxDEFO is Ob1101_1110_1111_0000 Call Stack - Locals PDebug (printf) Viewer Memory 1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems On GPUs In Databases

Authors: Johns Paul ,Shengliang Lu ,Bingsheng He

1st Edition

ISBN: 1680838482, 978-1680838480

More Books

Students also viewed these Databases questions