How to find a variable in a hex editor

1.3k views Asked by At

My goal is to be able to change the value of a calibration variable externally (using a hexadecimal editor). I have used the Arduino IDE to develop my code.

The variable, defined as a float, is called corrector and is definded as a global variable before the setup(): float corrector;

In the setup() I first define it's value: corrector = 1.0f;

Afterwards, I print the hex address where the variable is located : Serial.print("\tAddress: "); Serial.println((unsigned int)(&corrector), HEX);

The address I get is 309, and when I look at this address at the hex editor what I find is a 30, which means a 0 (wrong because I gave the value of 1 to the variable).

I would appreciate if someone could tell me if I am doing well or not.

Thank you.

1

There are 1 answers

0
Botje On

A float value of "1.0f" is represented as four bytes 3f800000 (possibly in reversed order if your platform is little-endian) Since this is a global variable without initializer, its address is very probably the runtime address, not the address in the binary.

If you change the definition like this:

float corrector = 1.0f;

You should be able to find those bytes in your binary at the place where the corrector symbol is in your symbol table.