Is it possible to delete a bit? Bit operations question.

Good afternoon all

I was hoping someone may be able to help me please, I don't have any useful code to post but hopefully that won't be necessary.

I have an unsigned int which contains 25 bits of data.
bit 10 of that number is effectively a check bit and I need to 'delete' it making the number 24bit. It is always 1

I don't want to just change it to zero I want to remove it.
I've read about bitshift but that would clear LSB or MSB? Can bitshift be started at a particular place?

Many thanks in advance for any pointers.

You're correct, you can't delete a bit, but you can use mask and shift operators to rearrange the variable.

Thanks for the clarification, I've solved this now by shifting as you suggested. I split the variable into three bytes, shifting the unwanted bit out of the way.

Thanks

If I understand right you have a binary number of 25 bits
and you want to delete bit number 10

if you do a bitwise-AND-operation

any bit that is 1 in your variable stays one as 1 & 1 = 1
and any bit in your variable that is 0 stays 0 because 0 & 1 = 0

       20          10
    5432109876543210987654321
mynr1011101010111101101110111
mask1111111111111110111111111

if you do mynr & mask the result is
mynr1011101010111100101110111

If you would like to keep bits 26 up to 31 the bitmask has all bits 1 exept for bit 25 that is 0 and then any bit inside your variable stays with its value except bit 10

      30        20          10
    21098765432109876543210987654321
mynr11100001011101010111111101110111
mask11111111111111111111101111111111
res 11100001011101010111101101110111

again with a small number to see the principle
mynr1011
mask1101
res 1001

that's what I would call "deleting" a single bit

best regards Stefan

I have an unsigned int which contains 25 bits of data.

Which Arduino board are you using and where did this int come from ?

Why the obsession with bytes?
The compiler knows how to do 32 bit shifts.

StefanL38:
If I understand right you have a binary number of 25 bits
and you want to delete bit number 10

lazerjules:
I don't want to just change it to zero I want to remove it.

lazerjules:
I've read about bitshift but that would clear LSB or MSB? Can bitshift be started at a particular place?

There's a gotcha when right shifting. Left shift and right shift operators ('<<' and '>>') | Microsoft Learn