0

I have a integer value e.g. : int data_value = 1150; I want to split this into two binary variables like this: value is binary_data_value 0X04,0X7E It just needs to be 2 binary values which, are 8 bits long each.

How is it best to go about this?

Thanks

Thomas Morris
  • 77
  • 2
  • 10
  • 5
    `data_value & 0xFF` and `(data_value >> 8) & 0xFF` – goodvibration Dec 09 '19 at 10:12
  • This is exactly what I wanted thank you. Fyi this is what i did with it: `int t1_value_1 = (T1_value >>8) & 0XFF;//MSB shifting int t1_value_2 = T1_value & 0XFF;//LSB int t2_value_1 = (T2_value >> 8) & 0XFF;//MSB int t2_value_2 = T2_value & 0XFF;//LSB ` – Thomas Morris Dec 09 '19 at 10:19
  • 2
    Does this answer your question? [How to get the value of individual bytes of a variable?](https://stackoverflow.com/questions/8680220/how-to-get-the-value-of-individual-bytes-of-a-variable) – Maxim Sagaydachny Dec 09 '19 at 10:39
  • 1
    Just make sure to never use bit shifts on signed types. `int` is signed. – Lundin Dec 09 '19 at 11:33

0 Answers0