Go Down

Topic: integer save into single bytes (Read 2 times) previous topic - next topic

AWOL

You can't add an L to a variable, the suffix is only used when specifying constants.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

GekoCH


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


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

AWOL

Using bit shifts, multiplication/division, unions or pointers.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

GekoCH

yes I tried bit shifts with:

Code: [Select]

  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....

AWOL

0, 8, 16,...32?

Why do your buffer subscripts start at 1?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up