-5

i am doing corebluetooth application and able to receive the data from the peripheral in the hex format i need to parse the data to integer format and is there any method to convert the data to integer format from hex format please help Below values iam getting

NSstring *data is

011f6d000000160000000000040507010500054607db051705173a0600053d
      Nslog(@"data is  Ð`@PpPT`}°QpQs")

And also please help if there is any method for converting the data to the string also.

Sport
  • 8,570
  • 6
  • 46
  • 65
iosdeveloper
  • 99
  • 3
  • 13
  • How many integers are in that hex string? What are their sizes? 8 bits 16? 32? Are they big-endian or small endian? – Paulw11 Jan 19 '15 at 11:35
  • above data cointains the 25 integer values i am using the byte array to the peripheral and in response to that i am getting those values – iosdeveloper Jan 19 '15 at 11:39
  • There are 31 bytes there, so how do you get 25 'integers'? And again, 'integer' isn't very helpful - are they bytes, int16, int32? a mixture – Paulw11 Jan 19 '15 at 11:44
  • 1
    You really need to copy/paste the code so there are not typos. Also how you printed the hex string. Also naming a `NSString` variable `data` just causes confusion. – zaph Jan 19 '15 at 11:44
  • I assume that you receive data and the hex is just because of the way you displayed it. Also if there are 31 bytes and 25 integers then some of the "integers" must be 8-bit and others larger, please provide the format you are expecting from the documentation. – zaph Jan 19 '15 at 11:46
  • its not copy paste zaph i have converted the charatacterstica.value to string from hex data.So i think its clear that i need to convert either the characteristic.value to integer format or string data to integer format. – iosdeveloper Jan 19 '15 at 12:59

1 Answers1

0

Define a struct with all the correct types and order. Point the struct to the data. Then just access the items via the struct elements. Be careful with the types, it is probably best to use well defined types such as int8_t, uint8_t, uint16_t, int16_t, etc to insure the correct element size. You will want a "packed" struct, not alligned to the CPU alignment size.

zaph
  • 111,848
  • 21
  • 189
  • 228