Go Down

Topic: combine vars ? (Read 410 times) previous topic - next topic

i need to combine two vars. but not add them together. any i
deas?
Thanks for your time.

JimboZA


any ideas?


No, because I don't know what you mean....

Maybe if you show an example?
"Could you do the egg bacon spam and sausage without the spam then? "

No PMs for help please.
DO NOT power servos from Arduino 5V: give them their own power and connect the grounds.

pYro_65

More info is needed, but here is a guess:

You maybe want two integers stored together, a simple bit shift might do.
Code: [Select]


uint8_t A;
uint8_t B;

uint16_t C =( A << 8 ) | B;

i have a 12 chanel remote conected to my arduino. i found out i need more the 12 buttons to do all the things i need to do. so i was thinking thar i could use a var to catch the input. that works great for 1-9 but how to hande double digets? i cant add them up becuse, say i whated function 23. if input 1 = 2 and input 2 = 3 and u add them input1 + input3 it will = 5 i need to combinde them so i get a value of 23.
Thanks for your time.

UKHeliBob

Seeing your code would help.
What do the other 3 buttons send ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

pYro_65

If your numbers are decimal ( base 10 ),

then simply:
Code: [Select]
#define BASE 10
int A = 2;
int B = 3;

int C = A * BASE + B;

PeterH


i have a 12 chanel remote conected to my arduino. i found out i need more the 12 buttons to do all the things i need to do. so i was thinking thar i could use a var to catch the input.


You could either put the values in an array (one element per switch) or store them as bits in an integer big enough to hold all of them (the standard types give you 8, 16, 32, 64 bits to choose from).

The array would be easier to access but take more space, which would only be an issue if you are short of memory or need to send these values over a communications link at high speed.
I only provide help via the forum - please do not contact me for private consultancy.

Go Up