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

php - Creating canonical URLs with custom route-classes -

Mysql Local server hardware -

mysql - Formatting problem with PHP DateTime Difference when used as part of an equation -