0

Question
Is there a way to set MSB of a number to 0 ...?..

Comments
  • 2
    Answer: Yes
  • 0
    @ItsNotMyFault well ....can u explain how?
  • 2
    @spdhiraj99

    if you know the size you can just use a bitmask
    for 8 bit unsigned integers you can do
    x &= 0b01111111;

    for unsigned integers in general you can shift the number left and then shift it back right again
    x = (x<<1) >> 1;
  • 1
    Make a loop in which u test bits for example numbe 15 is 00001111 so u check 128 false then go lower 64 32 16 8 now 8 is set so u set it to 0
    If i got correctly what u mean

    Edit:
    Or u just shifting the number left til its same then right
  • 1
    Depending on how big the number is (bit size).. you can do this:

    (ex for 8 bit byte data type):

    Num = 11011011

    Num & 0xFE = 11011010

    If the number is 16 bit do this:
    Num & 0xFFFE

    Etc..
Add Comment