integer save into single bytes

I don't recommend that you use "pow" for integer work.

Why is it working without an 'L'???

Why is it working with an L where? We can't see where you call that function.

It was suggested to add an 'L' behind my long number however it is also working without since I'm not
sure how I can add an 'L' behind a long variable....

You can't add an L to a variable, the suffix is only used when specifying constants.

AWOL:
I don't recommend that you use "pow" for integer work.

So how do you suggest to decode a 32bit value?

Using bit shifts, multiplication/division, unions or pointers.

yes I tried bit shifts with:

  unsigned long b1 = buffer[1] * 1 << 32;
  unsigned long b2 = buffer[2] * 1 << 16;
  unsigned long b3 = buffer[3] * 1 << 8;
  unsigned long b4 = buffer[4] * 1 << 0;
  unsigned long val = b1 + b2 +b3 + b4;

but didn't worked therefore i switched to pow....

0, 8, 16,...32?

Why do your buffer subscripts start at 1?

AWOL:
Why do your buffer subscripts start at 1?

Since in the first ([0]) is the adress where the message came from...

is 1 << 0 not the same as pow(256,0).

Or how can I do it differently?

1 << 0 is exactly the same value as 2560
The problem lies with the progression
0, 8, 16 ... ?

so maybe 24 hmmmm :slight_smile:

But still no success or is it still wrong (24)?

I'm posting this from my phone.
I can't see your results, and I'm miles from my Arduinos.

Hi,
if you are trying to convert from byte array to long integer, simply use the union in the opposite way:

   Number Out;

   Out.barray[0] = b0;
   Out.barray[1] = b1;
   Out.barray[2] = b2;
   Out.barray[3] = b3;

   unsigned long val = Out.num

ea123:
Hi,
if you are trying to convert from byte array to long integer, simply use the union in the opposite way:

   Number Out;

Out.barray[0] = b0;
   Out.barray[1] = b1;
   Out.barray[2] = b2;
   Out.barray[3] = b3;

unsigned long val = Out.num

Wow thx the union thing worked just great!

Finally I do need to send float numbers separated in a 4 byte array with the IEEE-754 Standard.
Converting form the bytes to float was easy but the other way round seems harder...

Finally I do need to send float numbers separated in a 4 byte array with the IEEE-754 Standard.
Converting form the bytes to float was easy but the other way round seems harder...

Why? It's the same union, with a float added.

wow you were right hmm this union thing is quite strong have to dig deeper what else it can deliver....

Thx
Andy

GekoCH:
So I tryed this but it doesn't work...

long number = 115730;

data[0] = (byte)(number >> 24);
data[1] = (byte)(number >> 16);
data[2] = (byte)(number >> 8);
data[3] = (byte)(number);

I don't see anything wrong with the original construction (aside from the ':' vs ';', which I hope is a transcription error.)
In what was does it "not work"?

the value returned was wrong compared to what was expected there fore I wrote it doesn't work...

the value returned was wrong compared to what was expected there fore I wrote it doesn't work...

Could be that your expectations were wrong. No input, no output, no way for us to know whether the code is wrong or your expectations are wrong.