Re: Convert int to char array (easy but...)



On 30 nov, 14:47, Thomas Fritsch <i.dont.like.s...@xxxxxxxxxxx> wrote:
clinisbut wrote:
What I want to do exactly is this:

I need to split (in a binary way) an Int into two bytes.
Something like:

int value : 340
same value in binary: 101010100

convert this to 2 bytes:
byte1 = 2 ( 1 in binary );

byte1 = 1 ( 1 in binary );

byte2 = 84 ( 1010100 );

I'm trying to do this but does not work:
byte1 = value>>8;
byte2 = value & 0x00FF;

But gives me wrong values... What I'm doing wrong!?

You calculated wrong byte1. See above.
I get byte1=1 and byte2=84.

--
Thomas

Sorry, obviously I misstyped 1...
.