0

I have int values of two bytes for example 254 = 0xFE, 112 = 0x70. I need to convert them to signed short. Now the signed short value should be -400.

And then after changing that value I have an integer for example -410 that i need to convert back to two bytes.

How could i achieve that for iOS?

Roo
  • 613
  • 1
  • 7
  • 24
  • objective-c is not c++ and c++ is not objective-c. You need to specify which language you're using – Astinog Sep 10 '15 at 10:21

1 Answers1

2

If the bytes are in the native architecture endianness, then it's as simple as

uint8_t *p = someAddress;
short value = *(short *)p;

value = 410;
*(short *)p = value;

However if the bytes are in a foreign endianness you are required to convert each byte of the integer, which is slow. Here is one, of many, examples.

Community
  • 1
  • 1
trojanfoe
  • 120,358
  • 21
  • 212
  • 242