1. ## Daft Question Time

if i declare the following:

static char sendData[8];

is sendData[0] possible of contain a 8bit hexidecimal number, such as

sendData[0] = 0x6085
sendData[1] = 0x6060
sendData[2] = 0
sendData[3] = 0x5085

etc

I would have assumed this to be simple but i cant get it to work.

Thanks

James

2. Originally Posted by r_james14
is sendData[0] possible of contain a 8bit hexidecimal number, such as
Yes, but these:

Code:
```sendData[0] = 0x6085
sendData[1] = 0x6060```
Are not 8-bit hex numbers, they are 16 bits*. You need two bits for each digit in a hexadecimal number, but nb. that is presuming an unsigned type.

* well, 0x6085 is less than 32768 and so would fit in 15-bits (ie, a signed 16-bit type), but hopefully you see the point.

3. Originally Posted by r_james14
if i declare the following:

static char sendData[8];

is sendData[0] possible of contain a 8bit hexidecimal number, such as

sendData[0] = 0x6085
sendData[1] = 0x6060
sendData[2] = 0
sendData[3] = 0x5085

etc

I would have assumed this to be simple but i cant get it to work.

Thanks

James
Redclare your array as... static unsigned short sendData[8]; ... or use smaller numbers...

4. ahhh yeah sorry, explains a awful lot now, next related question, is there a easy way to print this sendData in the following form

SendData[0]=0x00c3;
SendData[1]=0x00c4;
SendData[2]=0x00c5;
SendData[3]=0x00c6;
SendData[4]=0x00c7;

So it prints c3c4c5c6 and not combines them without having to put SendData[0]SendData[1] etc

5. Originally Posted by r_james14
ahhh yeah sorry, explains a awful lot now, next related question, is there a easy way to print this sendData in the following form

SendData[0]=0x00c3;
SendData[1]=0x00c4;
SendData[2]=0x00c5;
SendData[3]=0x00c6;
SendData[4]=0x00c7;

So it prints c3c4c5c6 and not combines them without having to put SendData[0]SendData[1] etc
Lose the 00 from each value... Yes they will fit in a char type, but the notation is deceiving... 0xc3 0xc4 etc.

You want to print them like above?..
Code:
```for (int i = 0; i < 5; i++)
printf("SendData[%d] = 0x%x\n", i, SendData[i]);```

6. Thanks that worked brilliantly.

Currently im trying to write code to send over Cnopen protocol which its dataset is split into 7 bytes, hence having to be specific to where the data is kept and in correct order.
Thanks Again

7. Make sure you declare your data as unsigned, otherwise

printf ("%x", SendData[i])

may sign-extend when it casts from char to int and give you something like FFFFFFC7. If you're only dealing with 7-bit data, though, the high bit will never be set you'll be OK, but best to be safe here.