Is it possible to set a bit pair to zero in an integer using

Creating a new topic here requires registration. All other forums are without registration.

Is it possible to set a bit pair to zero in an integer using

Postby Psevdosoul » Sun Apr 16, 2023 6:38 am

Is it possible to set a bit pair to zero in an integer using arithmetic?
Psevdosoul
 
Posts: 2
Joined: Sun Apr 16, 2023 6:36 am
Reputation: 0

Re: Is it possible to set a bit pair to zero in an integer u

Postby Psevdosoul » Sun Apr 16, 2023 7:09 am

Psevdosoul wrote:Is it possible to set a bit pair to zero in an integer using arithmetic?


Is it possible to zero paired bits in an integer using arithmetic?

Psevdosoul
 
Posts: 2
Joined: Sun Apr 16, 2023 6:36 am
Reputation: 0

Re: Is it possible to set a bit pair to zero in an integer u

Postby Guest » Sun Apr 16, 2023 2:32 pm

x = x & 0b11100111

In this example, the binary number 0b11100111 is the mask that has the 3rd and 4th bits set to zero and all other bits set to one. The bitwise AND operation with this mask will set the 3rd and 4th bits of x to zero, while leaving all other bits unchanged.
Guest
 

Re: Is it possible to set a bit pair to zero in an integer u

Postby Румен Симеонов » Wed Apr 19, 2023 7:25 am

The prolem might not be clearly enought stated and needing some justification. ,,Bit pair" ,,in an integer" could mean, according to my understanding, a number [tex]x[/tex] written or ,,appropriately kept" ,,in an integer variable" [tex]n[/tex] having in 2-adic system 2 digits, possibly with leading zeros. If this agreed then [tex]x\in \{ 0,1,2,3 \}[/tex] and a possible solution could be the ,,arithmetic": [tex]n:=n(n-1)(n-2)(n-3)[/tex]. or even simpler ,,arithmetic": [tex]n:=0+0[/tex]. If the 2 bits are not the first 2 right to left, then i don't see purely arithmetic function performed on the variable [tex]n[/tex] which solves the problem, always keeping the other bits of [tex]n[/tex] unchanged. Moreover, in such a case, the input would not be simply [tex]n[/tex] but needs to be more complex indicating the position of the two bits, after justifying the problem. It also needs justification if shifting bits is considered as arithmetic operation, depending on the computer language you have in mind, but didn't disclose to us.

Румен Симеонов
 
Posts: 5
Joined: Wed Apr 19, 2023 6:30 am
Reputation: 7


Return to Math Problem of the Week



Who is online

Users browsing this forum: No registered users and 6 guests