0
String abc ="0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff";

const unsigned char displaydata={reinterpret_cast<const unsigned char*>(abc.c_str())};

display.drawBitmap(displaydata, startX, startY, bmpWidth, bmpHeight, GxEPD_WHITE);

Get error: invalid conversion from 'const unsigned char' to 'unsigned char' [-fpermissive]*

When I write like this

String abc ="0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff";

display.drawBitmap(reinterpret_cast<const unsigned char*>(abc.c_str()), startX, startY, bmpWidth, bmpHeight, GxEPD_WHITE);

No error but black screen no display image

When I write like this

const unsigned char displaydata[]={ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};

display.drawBitmap(displaydata, startX, startY, bmpWidth, bmpHeight, GxEPD_WHITE);

It is working

The string data coming from the server is returning to me as stirng, I am trying to reflect it on the screen. I want to convert a string data to const unsigned char with code

So I'm trying to convert

5
  • How exactly is the server giving you the binary data? Please include an example string from the servers answer to the request. Is it really in the format of your first string?
    – chrisl
    Sep 25 at 14:19
  • With const unsigned char displaydata={reinterpret_cast<const unsigned char*>(... you're assigning a pointer to a single character. Or more importantly, part of a pointer to a character, which if the memory address (pointer value) was larger than 0xFF would be pretty useless. So, the problems start here with a missing pointer declarator (a *) There's not much Arduino to the question. Fairly squarely a C++ question, unless I'm missing something.
    – timemage
    Sep 25 at 15:49
  • 1
    String is a custom Arduino class, so could be classed as an arduino question (pun intended) on that merit.
    – Majenko
    Sep 25 at 16:10
  • Step one: Split the String into chunks using the comma delimiter. Step B: convert each chunk from its textual representation into its numeric value. Step Delta: place that value into the array. Step 0: forget const, that's irrelevant.
    – Majenko
    Sep 25 at 16:12
  • @Majenko, I didn't feel strongly enough about it to close-vote it.
    – timemage
    Sep 25 at 16:28
1

That string is literally the characters 0xff ... while the array is the bytes 0xff...

Where the string contains 4 bytes to say 0,x,f,f (followed by comma and space) the array will have 1 byte the 255 (and no need for a comma or space to delimit).

If you are looking to convert the text hex string to bytes, look at a combination of How to convert an hex string to an array of bytes? and looping through the string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.