A pretty basic Hex conversion problem

So I have some Bluetooth module in which I have to set some registers to get an effects, the table is here on page 14 :

The table is basically like this :

CHARACTERISTIC BITMAP:

EXTENDED 0X80
AUTENTICATED 0X40
INDICATE 0X20
NOTIFY 0X10 
WRITE 0X08
WRITE WITHOUT 0X04
READ 0X02
BROADCAST 0X01

What I don't get here, is that if I want to get the effect of : NOTIFY and WRITE WITHOUT
I have to set 14 to the register.

But ! 14, can also mean: WRITE + WRITE WITHOUT + READ

Which is a totally different set that I don't want.

How do you really set a register with this table ? for example, whats the effect of 14 ? first or second ?

Thanks.

Notice the 0x at the beginning of the numbers. That means they are interpreted as hexadecimal.

Do this to make it easy on yourself:

#define RN4020_EXTENDED 0X80
#define RN4020_AUTENTICATED 0X40
#define RN4020_INDICATE 0X20
#define RN4020_NOTIFY 0X10 
#define RN4020_WRITE 0X08
#define RN4020_WRITE_WITHOUT 0X04
#define RN4020_READ 0X02
#define RN4020_BROADCAST 0X01

Then to make a composite value, you just add the macro symbols: RN4020_NOTIFY + RN4020_WRITE_WITHOUT

Thanks a lot but this was not my question, I am trying to understand the exact difference in my question.

I have to set 14 to the register.

This is the mistake in thinking. In C++ there is a difference between 14, 0x14, and 014 (yes, the leading 0 makes a difference). The first is a decimal constant, the second a hexidecimal constant, the 3rd an octal constant. All three are different numbers.

0x10 + 0x4 is not 14, it is 0x14. 14 is equal to 0xE, and 0x14 is equal to 20.

How do you really set a register with this table ?

The best way it to do what I showed you, use #define to give names to the constants and either add (+) or bitwise-or (|) them together.

for example, whats the effect of 14 ? first or second ?

The second, because 14 is equivalent to 0xE.

It's a problem of you not thinking in hex :wink: Hex is not a variable type, it's just a way o represent a value. Like in languages one, un, Uno, ein, één etc mean the same thing in different languages. The 0x in front tells the compiler (and you) it's hex. And hex does not roll over after 9 :wink: It rolls over after F. So 0x8 + 0x4 = 0xC and 0xC + 0x2 = 0x8 + 0x4 + 0x = 0xE, not 0x14 :wink:

0x10 + 0x4 = 0x14 but in decimal it's 16 + 4 = 20

Unless whatever is reading the value requires a hex number, you could also use decimal values:

#define RN4020_EXTENDED          128         // 0x80
#define RN4020_AUTENTICATED       64         // 0X40
#define RN4020_INDICATE           32         // 0X20
#define RN4020_NOTIFY             16         // 0X10 
#define RN4020_WRITE               8         // 0X08
#define RN4020_WRITE_WITHOUT       4         // 0X04
#define RN4020_READ                2         // 0X02
#define RN4020_BROADCAST           1         // 0X01

which might make it easier to understand