objective c - How to append the bytes of a bit-field to NSMutableData -


मेरे पास एक स्ट्रक्चर

  typedef struct {int8_t foo: 1; } बार;   

मैंने बाइट्स को एक NSMutableData ऑब्जेक्ट के समान जोड़ने की कोशिश की है:

  NSMutableData * data = [[NSMutableData alloc] init]; बार अस्थायी; Temp.foo = 1; [डेटा संलग्नक: & amp; temp.foo लंबाई: sizeof (int8_t)];   

लेकिन मुझे बिट-फील्ड का पता करने का एक त्रुटि प्राप्त हुई। मैं बाइट को कैसे जोड़ सकता हूं?

बाइट को इंगित करें, आवश्यक बिट को मुखौटा दें, और चर संलग्न करें एक बाइट के रूप में:

  टाइपिंगफ़ाइल संरचना {int8_t foo: 1; } बार; NSMutableData * डेटा = [[NSMutableData alloc] init]; बार अस्थायी; Temp.foo = 1; Int8_t * p = (int8_t *) (और अस्थायी + 0); // बाइट को शिफ्ट करें आपको int8_t pureByte = * p & amp; 0x01; // मास्क को आप की ज़रूरत होती है [डेटा एपेंडबिट्स: & amp; शुद्धबैटे लंबाई: आकारफ (int8_t)];    

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

ruby on rails - Convert a Activerecord result with has_one associations into a single hash per record -

javascript - Read complete data from stream from onMessage -