当前位置: 动力学知识库 > 问答 > 编程问答 >

iphone - How to convert UISlider and accelerometer data to 16 bit char HEX in xcode/Objective C

问题描述:

I need to convert an UISlider value and my iPhones accelerometer data to a char in format char hexData = {0x00, 0x00, 0x01, 0xA0}. Any ideas on this?

The accelerometer values are signed (positive and negative) numbers, while the UISlider value spans from 0 to 100.

Thank you

网友答案:

well, i don't know what endianness the data is expected to be sent in; you may have to reverse the order.

but you should be able to get away with simple C manipulations such as the following.

    char fourChar[4];
    int* value = (int*)(&fourChar);
    *value = (int)floatValueFromSlider;  // or the simple values from your picker
    [appNote sendCharArray:fourChar];    // assuming the method wants a char[] of only 4 characters

this will be in little-endian format. you will probably have to swap the bytes before sending, depending upon what the receiver expects. you can manipulate this further as necessary.

分享给朋友:
您可能感兴趣的文章:
随机阅读: