A
A
Alexander Urich2018-03-02 23:08:22
Arduino
Alexander Urich, 2018-03-02 23:08:22

How to convert number c++?

Hello. I started to get interested in MK programming, but I still can't get into the language.
There is a WS2812FX library that implements getting some current data, in particular getting the current color:

uint32_t WS2812FX::getColor(void) {
  return _segments[0].colors[0];
}

And also setting the color:
void WS2812FX::setColor(uint32_t c) {
    RESET_RUNTIME;
    _segments[0].colors[0] = c;
    setBrightness(_brightness);
}

In the sketch, the color is set like this:
uint32_t tmp = (uint32_t) strtol(&server.arg(i)[0], NULL, 16);
if(tmp >= 0x000000 && tmp <= 0xFFFFFF) {
        ws2812fx.setColor(tmp);
}

That is, in server.arg(i)[0] the HTML color comes in the form FF0000
What is my snag:
I get the current color ws2812fx.getColor() and give it to http, but a completely different value comes: for the set white color (FFFFFF) the number 16777215 comes in - this is the maximum number of unsigned int, and, for example, for green (00FF00) - this is the number 65280
In general, the question is: How can I get the HTML color code from this number?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
1
15432, 2018-03-03
@Urichalex

0xFFFFFF is the hexadecimal representation of the decimal number 16777215, just
like 0xFF00 is 65280 in decimal.
Even the Windows calculator in "programmer" mode has the feature of converting number systems
in C. You can print a number in HEX form using printf("%X", number)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question