-2

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 ?

Community
  • 1
  • 1

1 Answers1

2

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

Community
  • 1
  • 1
Mahmoud Fayez
  • 3,398
  • 2
  • 19
  • 36