Pages: [1]   Go Down
Author Topic: combine vars ?  (Read 323 times)
0 Members and 1 Guest are viewing this topic.
Dunkirk NY
Offline Offline
Newbie
*
Karma: 0
Posts: 43
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

i need to combine two vars. but not add them together. any i
deas?
Logged

Thanks for your time.

Online Online
Faraday Member
**
Karma: 80
Posts: 3804
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

any ideas?

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

Maybe if you show an example?
Logged

Although I answer in good faith, remember always: Your Mileage May Vary.
Get me on LinkedIn: za.linkedin.com/in/jimbrownza/

North Queensland, Australia
Offline Offline
Edison Member
*
Karma: 64
Posts: 2101
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

More info is needed, but here is a guess:

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

uint8_t A;
uint8_t B;

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


Dunkirk NY
Offline Offline
Newbie
*
Karma: 0
Posts: 43
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Thanks for your time.

East Anglia (UK)
Online Online
Faraday Member
**
Karma: 109
Posts: 4040
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Seeing your code would help.
What do the other 3 buttons send ?
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

North Queensland, Australia
Offline Offline
Edison Member
*
Karma: 64
Posts: 2101
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If your numbers are decimal ( base 10 ),

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

int C = A * BASE + B;
Logged


UK
Offline Offline
Shannon Member
****
Karma: 222
Posts: 12541
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Pages: [1]   Go Up
Jump to: