Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a function names convert_uint16_number_to_binary_str which converts a uint16 num to a string of binary bits and save the results to cPtr. _________________________________________________________________________ _________________________________________________________________________ _________________________________________________________________________in

Write a function names convert_uint16_number_to_binary_str which converts a uint16 num to a string of binary bits and save the results to cPtr. _________________________________________________________________________ _________________________________________________________________________ _________________________________________________________________________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.

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

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions