Go Down

### Topic: Counting hexadecimal / binary (Read 4885 times)previous topic - next topic

#### ritzdank

##### Jan 29, 2007, 04:28 pm
for example, if i have an register 0x00 and i want to count up to let´s say 0xff each step in a loop ?? i want to make a function and just pass the variable between the increasing steps (0x01,0x02,....0xdf, 0xef,0xff).

any code out there? don´t even know how to start!

thanks

#### kg4wsv

#1
##### Jan 29, 2007, 04:40 pm
like this?

Code: [Select]
`int i;for (i = 0x0; i <=0xff; i++){    fn_whatever(i);}`

-j

#### ritzdank

#2
##### Jan 29, 2007, 06:05 pm
yeah! great! well, i was also interested in a solution writtten in C, as i it wouldnt be that easy like the above.

but thanks a lot! it works.

#### kg4wsv

#3
##### Jan 29, 2007, 06:46 pm
Quote
i was also interested in a solution writtten in C, as i it wouldnt be that easy like the above.

I don't understand this statement; that is C code.  Of course, being C, it's also C++, "Arduino" code, etc.

C doesn't care if the constants are hex (0xff), octal (075), decimal (6789), or even ASCII ('c').  It doesn't know about binary constants, but somone wrote a macro to handle that, I think included in Arduino 7.

-j

#### ritzdank

#4
##### Jan 29, 2007, 11:59 pm
sorry, you are right! but i´ve another question which is hard to find through all references. how can i "eval" within arduino language. for example, i have some registers called reg_level0, reg_level1, reg_level2 ...
i want to set some bytes in a for-statement such as

Code: [Select]
`for (i = 0; i < 5; i++) {function_blablab(reg_level[i], 0x00);}`

of course above example couldnt be compiled as it interprets the square brackets as an array? do you know another syntaa for that?

thanks

#### kg4wsv

#5
##### Jan 30, 2007, 12:07 am
I don't think what you're asking is possible.

My first thought is to put them into an array instead of having several discrete values.

-j

#### ritzdank

#6
##### Jan 30, 2007, 12:39 am
yep, workaround is indeed an array, here´s the code

Code: [Select]
`byte reg_level0 = 0x01;byte reg_level1 = 0x02;byte reg_level2 = 0x03;byte reg_level3 = 0x04;byte reg_level4 = 0x05;byte reg_level[5] = { reg_level0, reg_level1, reg_level2, reg_level3, reg_level4  };void test(int i) {for (i = 0; i < 5; i++)  {  function_blalba(reg_level[i], 0x40);  delay(delaytime); }}`

Go Up