to write in bits of register
hello people how may i write on a 32 bit register the value
int a=2 in the bit 19 until 31 (31,30,29,28,27,26,25,24,23,22,21,20,19).
set the bit:
a |= 1 << x; //where x is the bit?
reset the bit:
a &= ~(1 << x);
a ^= 1 << x;
int bitmask = 0x7FFC0000
on a 32 bit register
Do you mean a CPU register?
@ kshegunov no CPU register only data register what may i have to do with the bitmaske?
You can use it to mask the number:
int number = 2; int a = ((number << 19) & 0x7FFC0000);
@kshegunov i get trouble with that.because the value of number changed.
i want that the value d ont change
I'm sorry I don't understand, what value is changing and why?
@kshegunov kshegunov the fact ist: i want to send server data to a receiver. for example
we have server data like:
this three value have to be send to receiver , bevor that they have to be write on a 32bit Register with
certain position.for example value a between bit 19 and 32, value b between bit 0 and 4, value c between bit 7 and 9.
this value after be written in register,they have to be send(3 bytes) to receiver,because of that the value dont have to be change.
after shift operation i search a possibility to get the original value
So what's stopping you from masking the relevant bits and shift them accordingly?
int a = 2; int b = 3; int c = 0; int data = (b & 0x1F) | ((c & 0x7) << 7) | ((a & 0x1FFF) << 19); //< This would be the "register" you want.
Also an integer is the size of 4 bytes (32 bits), not 3.