Go Down

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

#### Slee_The_Sloth

##### Mar 23, 2013, 06:18 am
i need to combine two vars. but not add them together. any i
deas?
Thanks for your time.

#### JimboZA

#1
##### Mar 23, 2013, 06:22 am

any ideas?

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

Maybe if you show an example?
Johannesburg hams call me: ZS6JMB on Highveld rep 145.7875 (-600 & 88.5 tone)

#### pYro_65

#2
##### Mar 23, 2013, 06:38 am
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;`
Forum Mod anyone?
https://arduino.land/Moduino/

#### Slee_The_Sloth

#3
##### Mar 23, 2013, 09:07 am
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

#4
##### Mar 23, 2013, 09:22 am
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

#5
##### Mar 23, 2013, 09:54 am
If your numbers are decimal ( base 10 ),

then simply:
Code: [Select]
`#define BASE 10int A = 2;int B = 3;int C = A * BASE + B;`
Forum Mod anyone?
https://arduino.land/Moduino/

#### PeterH

#6
##### Mar 23, 2013, 02:05 pm

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.

Go Up