How can I assign bit by bit to an integer in C?
Possible Duplicate:
How do you set, clear and toggle a single bit in C?
I want to create an assembler , so I need to assign 32 bits bit by bit or field by field to create 32 bit opcode from assembly ... how can I do this in C ? how can I assign bits in integer ? can this be done ?
You can declare these two macros to help you:
#define Set_Bit(IntValue, BitNumber) IntValue = IntValue | (1<<BitNumber)
#define Clr_Bit(IntValue, BitNumber) IntValue = IntValue & (~((1) << (BitNumber))))
Some questions have discussed these before: Macros to set and clear bits
链接地址: http://www.djcxy.com/p/28804.html上一篇: 在第i个位置切换一下