Convert uint8_t to an ascii string C Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Is there a better way to size a buffer for printing integers?trying to copy a char pointer using memcpy, getting an errorC#, extract double from USARTs receive char bufferCppUTest: how to pass more data to a specific mock call?Confusions about if statement and strcmp with StringsSend converted DS1820 temperature over PIC16 uartC++ unsigned char array lengthC:Having some troubles with a pointer to uint8_t[]Sending a int8_t as a uint8_t without changing bit patternfacing a challenge writing my own and my_itoa and my atoi, which should change integer to ascii and vice versa in CVariable size of uint8_t array
Why is it faster to reheat something than it is to cook it?
Illegal assignment from sObject to Id
Disembodied hand growing fangs
Selecting user stories during sprint planning
How does Python know the values already stored in its memory?
Denied boarding although I have proper visa and documentation. To whom should I make a complaint?
Find 108 by using 3,4,6
If Windows 7 doesn't support WSL, then what does Linux subsystem option mean?
Using audio cues to encourage good posture
How to compare two different files line by line in unix?
How were pictures turned from film to a big picture in a picture frame before digital scanning?
Why is the AVR GCC compiler using a full `CALL` even though I have set the `-mshort-calls` flag?
What was the first language to use conditional keywords?
Converted a Scalar function to a TVF function for parallel execution-Still running in Serial mode
Why does it sometimes sound good to play a grace note as a lead in to a note in a melody?
Hangman Game with C++
How does light 'choose' between wave and particle behaviour?
ArcGIS Pro Python arcpy.CreatePersonalGDB_management
Dating a Former Employee
What is this clumpy 20-30cm high yellow-flowered plant?
Putting class ranking in CV, but against dept guidelines
What order were files/directories outputted in dir?
Why weren't discrete x86 CPUs ever used in game hardware?
Is there any word for a place full of confusion?
Convert uint8_t to an ascii string C
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!Is there a better way to size a buffer for printing integers?trying to copy a char pointer using memcpy, getting an errorC#, extract double from USARTs receive char bufferCppUTest: how to pass more data to a specific mock call?Confusions about if statement and strcmp with StringsSend converted DS1820 temperature over PIC16 uartC++ unsigned char array lengthC:Having some troubles with a pointer to uint8_t[]Sending a int8_t as a uint8_t without changing bit patternfacing a challenge writing my own and my_itoa and my atoi, which should change integer to ascii and vice versa in CVariable size of uint8_t array
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
Given the following function
UART_write(UART_Handle handle, const void *buffer, size_t size);
I want to send via uart a int8_t value ( log it )
What i tried:
int8_t value;
UART_write(uart, value, strlen(value));
const char *echoPrompt = (char *)value;
UART_write(uart, echoPrompt, sizeof(echoPrompt));
const char echoPrompt2[] = value;
UART_write(uart, echoPrompt2, sizeof(echoPrompt2));
const char* buff = value;
UART_write(uart, value, strlen(value));
The best i got is logging the hex value
Exemple of how the uart_write function works: In orded to log "12" what I need to do is
const uint8_t value[] = 0x31, 0x32;
UART_write(uart, value, sizeof(value));
So my question is, how to log my int8_t variable ( I need to log negative numbers as well)
c serial-port embedded uart
add a comment |
Given the following function
UART_write(UART_Handle handle, const void *buffer, size_t size);
I want to send via uart a int8_t value ( log it )
What i tried:
int8_t value;
UART_write(uart, value, strlen(value));
const char *echoPrompt = (char *)value;
UART_write(uart, echoPrompt, sizeof(echoPrompt));
const char echoPrompt2[] = value;
UART_write(uart, echoPrompt2, sizeof(echoPrompt2));
const char* buff = value;
UART_write(uart, value, strlen(value));
The best i got is logging the hex value
Exemple of how the uart_write function works: In orded to log "12" what I need to do is
const uint8_t value[] = 0x31, 0x32;
UART_write(uart, value, sizeof(value));
So my question is, how to log my int8_t variable ( I need to log negative numbers as well)
c serial-port embedded uart
1
Did you look here?
– alk
Mar 22 at 11:05
add a comment |
Given the following function
UART_write(UART_Handle handle, const void *buffer, size_t size);
I want to send via uart a int8_t value ( log it )
What i tried:
int8_t value;
UART_write(uart, value, strlen(value));
const char *echoPrompt = (char *)value;
UART_write(uart, echoPrompt, sizeof(echoPrompt));
const char echoPrompt2[] = value;
UART_write(uart, echoPrompt2, sizeof(echoPrompt2));
const char* buff = value;
UART_write(uart, value, strlen(value));
The best i got is logging the hex value
Exemple of how the uart_write function works: In orded to log "12" what I need to do is
const uint8_t value[] = 0x31, 0x32;
UART_write(uart, value, sizeof(value));
So my question is, how to log my int8_t variable ( I need to log negative numbers as well)
c serial-port embedded uart
Given the following function
UART_write(UART_Handle handle, const void *buffer, size_t size);
I want to send via uart a int8_t value ( log it )
What i tried:
int8_t value;
UART_write(uart, value, strlen(value));
const char *echoPrompt = (char *)value;
UART_write(uart, echoPrompt, sizeof(echoPrompt));
const char echoPrompt2[] = value;
UART_write(uart, echoPrompt2, sizeof(echoPrompt2));
const char* buff = value;
UART_write(uart, value, strlen(value));
The best i got is logging the hex value
Exemple of how the uart_write function works: In orded to log "12" what I need to do is
const uint8_t value[] = 0x31, 0x32;
UART_write(uart, value, sizeof(value));
So my question is, how to log my int8_t variable ( I need to log negative numbers as well)
c serial-port embedded uart
c serial-port embedded uart
asked Mar 22 at 10:32
andrei filipandrei filip
62
62
1
Did you look here?
– alk
Mar 22 at 11:05
add a comment |
1
Did you look here?
– alk
Mar 22 at 11:05
1
1
Did you look here?
– alk
Mar 22 at 11:05
Did you look here?
– alk
Mar 22 at 11:05
add a comment |
2 Answers
2
active
oldest
votes
You will need to convert your integer to string.
snprintf
is a standard way to do this, if your libc provides it.
add a comment |
Convert uint8_t to an ascii string C
Determine the maximum string size needed for any value of that type. Is there a better way to size a buffer for printing integers?
#define UINT_BUFFER10_SIZE(type) (1 + (CHAR_BIT*sizeof(type)*LOG10_2_N)/LOG10_2_D + 1)
Form the buffer
char buf[UINT_BUFFER10_SIZE(value)];
"Print" the uint8_t
to the buffer.
int len = sprintf(buf, "%d", value);
// or pedantically
int len = snprintf(buf, sizeof buf, "%" PRId8, value); // see <inttypes.h>
assert(len >= 0 && (unsigned)len < sizeof buf);
Send it
UART_write(uart, buf, len);
how to log my int8_t variable
#define INT_BUFFER10_SIZE(type) (2 + ((CHAR_BIT*sizeof(type)-1)*LOG10_2_N)/LOG10_2_D + 1)
char buf[INT_BUFFER10_SIZE(ivalue)];
int len = sprintf(buf, "%d", ivalue);
UART_write(uart, buf, len);
IMO, code should add a helper function to send a string
void UART_write_str(UART_Handle handle, const char *str)
UART_write(uart, str, strlen(str));
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55297698%2fconvert-uint8-t-to-an-ascii-string-c%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You will need to convert your integer to string.
snprintf
is a standard way to do this, if your libc provides it.
add a comment |
You will need to convert your integer to string.
snprintf
is a standard way to do this, if your libc provides it.
add a comment |
You will need to convert your integer to string.
snprintf
is a standard way to do this, if your libc provides it.
You will need to convert your integer to string.
snprintf
is a standard way to do this, if your libc provides it.
answered Mar 22 at 10:47
domendomen
1,215816
1,215816
add a comment |
add a comment |
Convert uint8_t to an ascii string C
Determine the maximum string size needed for any value of that type. Is there a better way to size a buffer for printing integers?
#define UINT_BUFFER10_SIZE(type) (1 + (CHAR_BIT*sizeof(type)*LOG10_2_N)/LOG10_2_D + 1)
Form the buffer
char buf[UINT_BUFFER10_SIZE(value)];
"Print" the uint8_t
to the buffer.
int len = sprintf(buf, "%d", value);
// or pedantically
int len = snprintf(buf, sizeof buf, "%" PRId8, value); // see <inttypes.h>
assert(len >= 0 && (unsigned)len < sizeof buf);
Send it
UART_write(uart, buf, len);
how to log my int8_t variable
#define INT_BUFFER10_SIZE(type) (2 + ((CHAR_BIT*sizeof(type)-1)*LOG10_2_N)/LOG10_2_D + 1)
char buf[INT_BUFFER10_SIZE(ivalue)];
int len = sprintf(buf, "%d", ivalue);
UART_write(uart, buf, len);
IMO, code should add a helper function to send a string
void UART_write_str(UART_Handle handle, const char *str)
UART_write(uart, str, strlen(str));
add a comment |
Convert uint8_t to an ascii string C
Determine the maximum string size needed for any value of that type. Is there a better way to size a buffer for printing integers?
#define UINT_BUFFER10_SIZE(type) (1 + (CHAR_BIT*sizeof(type)*LOG10_2_N)/LOG10_2_D + 1)
Form the buffer
char buf[UINT_BUFFER10_SIZE(value)];
"Print" the uint8_t
to the buffer.
int len = sprintf(buf, "%d", value);
// or pedantically
int len = snprintf(buf, sizeof buf, "%" PRId8, value); // see <inttypes.h>
assert(len >= 0 && (unsigned)len < sizeof buf);
Send it
UART_write(uart, buf, len);
how to log my int8_t variable
#define INT_BUFFER10_SIZE(type) (2 + ((CHAR_BIT*sizeof(type)-1)*LOG10_2_N)/LOG10_2_D + 1)
char buf[INT_BUFFER10_SIZE(ivalue)];
int len = sprintf(buf, "%d", ivalue);
UART_write(uart, buf, len);
IMO, code should add a helper function to send a string
void UART_write_str(UART_Handle handle, const char *str)
UART_write(uart, str, strlen(str));
add a comment |
Convert uint8_t to an ascii string C
Determine the maximum string size needed for any value of that type. Is there a better way to size a buffer for printing integers?
#define UINT_BUFFER10_SIZE(type) (1 + (CHAR_BIT*sizeof(type)*LOG10_2_N)/LOG10_2_D + 1)
Form the buffer
char buf[UINT_BUFFER10_SIZE(value)];
"Print" the uint8_t
to the buffer.
int len = sprintf(buf, "%d", value);
// or pedantically
int len = snprintf(buf, sizeof buf, "%" PRId8, value); // see <inttypes.h>
assert(len >= 0 && (unsigned)len < sizeof buf);
Send it
UART_write(uart, buf, len);
how to log my int8_t variable
#define INT_BUFFER10_SIZE(type) (2 + ((CHAR_BIT*sizeof(type)-1)*LOG10_2_N)/LOG10_2_D + 1)
char buf[INT_BUFFER10_SIZE(ivalue)];
int len = sprintf(buf, "%d", ivalue);
UART_write(uart, buf, len);
IMO, code should add a helper function to send a string
void UART_write_str(UART_Handle handle, const char *str)
UART_write(uart, str, strlen(str));
Convert uint8_t to an ascii string C
Determine the maximum string size needed for any value of that type. Is there a better way to size a buffer for printing integers?
#define UINT_BUFFER10_SIZE(type) (1 + (CHAR_BIT*sizeof(type)*LOG10_2_N)/LOG10_2_D + 1)
Form the buffer
char buf[UINT_BUFFER10_SIZE(value)];
"Print" the uint8_t
to the buffer.
int len = sprintf(buf, "%d", value);
// or pedantically
int len = snprintf(buf, sizeof buf, "%" PRId8, value); // see <inttypes.h>
assert(len >= 0 && (unsigned)len < sizeof buf);
Send it
UART_write(uart, buf, len);
how to log my int8_t variable
#define INT_BUFFER10_SIZE(type) (2 + ((CHAR_BIT*sizeof(type)-1)*LOG10_2_N)/LOG10_2_D + 1)
char buf[INT_BUFFER10_SIZE(ivalue)];
int len = sprintf(buf, "%d", ivalue);
UART_write(uart, buf, len);
IMO, code should add a helper function to send a string
void UART_write_str(UART_Handle handle, const char *str)
UART_write(uart, str, strlen(str));
edited Mar 22 at 14:50
answered Mar 22 at 14:44
chuxchux
85.3k874157
85.3k874157
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55297698%2fconvert-uint8-t-to-an-ascii-string-c%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Did you look here?
– alk
Mar 22 at 11:05