-5

Some one asked me this to how you can change/replace 8th position number to 0 in a 32 bit integer,Can I use left or right shift or what else any suggestion would be helpful.

This is not duplicate as far I am concerned with my specific problem for replacing a bit with 0, where as How do you set, clear, and toggle a single bit? on this link it is too broad from me related to this problem.

  • 3
    Ask your teacher to explain if you're having difficulties with your homework. If that *some one* was not your teacher, then tell them you don't know. – Ken White Mar 04 '18 at 04:36
  • I am expecting a suggestion to solve this – Shiwani Pandey Mar 04 '18 at 05:47
  • 2
    You are expecting us to do your homework. Some expectations lead to disappointment, I'm afraid. – Ken White Mar 04 '18 at 05:50
  • Can I have some reference, What should I read to solve this – Shiwani Pandey Mar 04 '18 at 05:54
  • https://stackoverflow.com/q/47981/62576 – Ken White Mar 04 '18 at 05:55
  • I am going through with this but their is a confusion:number ^= (-x ^ number) & (1UL << n); Bit n will be set if x is 1, and cleared if x is 0. If x has some other value, you get garbage. x = !!x will booleanize it to 0 or 1. This can set 1 only not 0 – Shiwani Pandey Mar 04 '18 at 05:58
  • 1
    Ask your teacher to explain if you're having difficulties with your homework. They are being paid to teach you. – Ken White Mar 04 '18 at 06:00
  • Possible duplicate of [How do you set, clear, and toggle a single bit?](https://stackoverflow.com/questions/47981/how-do-you-set-clear-and-toggle-a-single-bit) – phuclv Mar 04 '18 at 09:43

1 Answers1

0
binaryNum = binaryNum & ~ (1u << 7)

here binaryNum is your binary representation of number.

7(7 because it starts from 0) is the ith position where you wants to change.