Is there an easy way to read / write a nibble in a byte without using bit fields? I always need to read both nibbles, but you will need to write each piece individually.
Thank!
Use masks:
char byte; byte = (byte & 0xF0) | (nibble1 & 0xF); // write low quartet byte = (byte & 0x0F) | ((nibble2 & 0xF) << 4); // write high quartet
You may want to put this internal macro.
The smallest block you can work with is one byte. If you want to control bits, you must use bitwise operators .
- :
union ByteNibbles { ByteNibbles(BYTE hiNibble, BYTE loNibble) { data = loNibble; data |= hiNibble << 4; } BYTE data; };
:
ByteNibbles byteNibbles(0xA, 0xB); BYTE data = byteNibbles.data;
Source: https://habr.com/ru/post/1751573/More articles:How to use UUID but remain compatible with existing database identifiers? - sqlMac OS X Window Server против X11: безумная задача - cocoaProgrammatically check if IPv6 is enabled in windows - c ++Puzzle Sort List - javaIs Azure Shared Access Signature suitable, can anyone access my blobs? - .netWhat is the best denormalization practice in CQRS? - phpКогда использовать InterfaceBuilder для создания представлений? - objective-cjQuery простой запрос ajax не работает - javascriptКак получить параметр CLI от bash? - bashC90 - C99: register structure - cAll Articles