Go Down

Topic: Function Declaration Error (Read 2287 times) previous topic - next topic

BN.barak

Yes sir,
the command is the
  • and [1], the port is [2] and [3] and the value is [4][5][6].
    example :
    byte myCommand[] = {0,8,2,8,4,7,5};
    getCommand(myCommand) will get me:
    command = 08
    port = 28
    value = 475

    Thank you.

Eight

#16
Aug 25, 2010, 01:02 pm Last Edit: Aug 25, 2010, 01:06 pm by Eight Reason: 1
Ok, you'll probably want to do something different then; or you'll have to use a word long instead of int for value (3 x bytes is too much for an int).

Try some base10 math

iCommand = ((int)command[0] * 10) + (int)command[1]
iValue = ((int)command[4] * 100) + ((int)command[5] * 10) + (int)command[6]
etc. etc.

Edit: I said word, I meant long.

BN.barak

May you explain me more about thous lines please?

Eight

#18
Aug 25, 2010, 01:17 pm Last Edit: Aug 25, 2010, 01:19 pm by Eight Reason: 1
Well, if your command inputs are only from 0-9 (it won't work with numbers above 9) then you can combine them by multiplying.

E.g.

TWO DIGITS
Command[0] = 9
Command[1] = 5

9 * 10 = 90
+
5
= 95

THREE DIGITS
command[4] = 2
command[5] = 1
command[6] = 0

2 * 100 = 200
+
1 * 10 = 10
+
0
= 210

The (int) parts cast the byte to an int, because our maths will exceed the capacity of a byte.

If a single input e.g. command[0] can be greater than 9 then you might need to go back to bit shifting and using the long datatype.



Go Up