Bit Masking: How to Manipulate Bits in Binary Numbers

  • Context: MHB 
  • Thread starter Thread starter gEOdude
  • Start date Start date
  • Tags Tags
    Bit Operations
Click For Summary

Discussion Overview

The discussion revolves around the concept of bit masking in binary numbers, specifically focusing on manipulating bits within an 8-bit binary number. Participants explore how to turn off specific bits and toggle others, while also addressing potential misunderstandings in the problem statement.

Discussion Character

  • Technical explanation
  • Conceptual clarification
  • Debate/contested

Main Points Raised

  • One participant presents a problem involving the 8-bit binary number "1001 1101" and describes two tasks: turning off the outer 2 bits and toggling the middle 4 bits.
  • Another participant questions the phrasing of the problem, noting confusion about the reference to the middle 4 bits and the outer 2 bits, suggesting a potential inconsistency in the total count of bits.
  • A different participant expresses uncertainty about whether there is an error in the problem as stated by the teacher.
  • One participant clarifies that the reference to 2 bits on each side means 2 bits to the left and 2 bits to the right, confirming the total of 8 bits is correct.
  • There is a mention of a specific mask used for the operations, with one participant indicating a concern about the evaluation of the XOR operation in the context of toggling bits.

Areas of Agreement / Disagreement

Participants express confusion regarding the problem's wording, but there is a clarification that the total of 8 bits is indeed accounted for. However, there is no consensus on the correctness of the operations performed, particularly regarding the XOR operation.

Contextual Notes

Some participants highlight potential misunderstandings in the problem statement and the operations involved, but these remain unresolved. The discussion reflects varying interpretations of the task and the application of bit masking techniques.

gEOdude
Messages
25
Reaction score
0
Hey Guys, can i have a hand with this question. I just want to know if what I did was right.

Bit masking has a task. They are used in order to access specific bits in a byte of data.

1) Using the 8-bit binary number “1001 1101”:
Turn off the 2 bits (masking bits to 0) on each side, and then leave the middle 4 alone.The output should be achieved should be "0001 1100”.

2) Using the 8-bit binary number “1001 1101”:
Toggle the values of the middle 4 bits (the opposite of what it currently is), and leave the 2 bits on each side untouched.The output achieved should be"10100001”.
Answer
1) (1001 1101) & (0101 1110) = 0001 1100
2) (1001 1101) ^ (0111 1110) = 1010 0001
 
Technology news on Phys.org
HELPMEHELPME said:
1) Using the 8-bit binary number “1001 1101”:
Turn off the 2 bits (masking bits to 0) on each side, and then leave the middle 4
alone.

HELPMEHELPME said:
Toggle the values of the middle 4 bits (the opposite of what it currently is), and leave the 2 bits on each side untouched.
Why do these quotes talk about the middle 4 bits and the 2 bits on each side, that is, 6 bits in total, when the input number consists of 8 bits?
 
Im not sure, its how my teacher wrote the problem. Is there something wrong with it?
 
HELPMEHELPME said:
Bit masking has a task. They are used in order to access specific bits in a byte of data.

1) Using the 8-bit binary number “1001 1101”:
Turn off the 2 bits (masking bits to 0) on each side, and then leave the middle 4 alone.The output should be achieved should be "0001 1100”.

The mask that masks out 2 bits on each side is [m]0011 1100[/m].
Using this mask we can do:
1001 1101 & [m]0011 1100[/m] = 0001 1100

2) Using the 8-bit binary number “1001 1101”:
Toggle the values of the middle 4 bits (the opposite of what it currently is), and leave the 2 bits on each side untouched.The output achieved should be"10100001”.

Using the same mask:
1001 1101 ^ [m]0011 1100[/m] = 1010 0001
Answer
2) (1001 1101) ^ (0111 1110) = 1010 0001

I'm afraid the xor operator is not evaluated properly here. (Worried)

Evgeny.Makarov said:
Why do these quotes talk about the middle 4 bits and the 2 bits on each side, that is, 6 bits in total, when the input number consists of 8 bits?
HELPMEHELPME said:
Im not sure, its how my teacher wrote the problem. Is there something wrong with it?
No.
2 bits on each side means 2 bits to the left and 2 bits to the right, for 2+4+2=8 bits in total.
 
I like Serena said:
2 bits on each side means 2 bits to the left and 2 bits to the right, for 2+4+2=8 bits in total.
Of course. Sorry about my misunderstanding.
 

Similar threads

Replies
1
Views
4K
  • · Replies 19 ·
Replies
19
Views
3K
  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 2 ·
Replies
2
Views
11K
  • · Replies 2 ·
Replies
2
Views
13K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 34 ·
2
Replies
34
Views
22K
  • · Replies 2 ·
Replies
2
Views
2K