Basic conversions

OK, I a trying to do conversions

How do save a "value" into a word
such as word testingW="FF68" ??

then how do I convert it to an integer showing the - value ? (-152) - 2s complement, I think.

PLEASE NOTE: I am NOT wanting to print, just get a value o -152 that I can use in formulas etc. (not a Serial.print (testingW,DEC) type answer please).

Thanks in Advance

Graham

Hello arduinodumbo

 int testingW=0xFF68;

The CPU works with this variable regardless of whether the human would read it in decimal, hexadecimal, octal or whatever format.

Hi
Thanks for the first answer, howevr I did not understand the second half ??
I need to get a variable that I can multiply, divide etc.

Thanks

Yes, that would be useful for the microcontroller to take the data with which it should calculate or do whatever.

1 Like

output

-152

code

void
setup (void)
{
    Serial.begin (9600);
    int w = 0xff68;
    Serial.println (w);
}

void
loop (void)
{
}

The ONLY reason to convert it is for humans to view it.
If you don't wish to print or display it then you need not do anything.
to the Arduino it's all binary there is no other.

The 'word' data type is pretty obscure in C++. Better to use "int" or if you want to enforce 16 bits, "int16_t".

Is this a school assignment?

from Arduino.h

typedef unsigned int word;

I'm not saying it doesn't exist. I know. I just don't recommend it.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.