Extracting Bits from Variables in PIC Microcontrollers

  • Thread starter Thread starter Magna Visus
  • Start date Start date
  • Tags Tags
    Microcontroller
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 2K views
Magna Visus
Messages
23
Reaction score
0
Hello guys!

The following question is related to the P18F2520 series.

Suppose you have 2 defined variables var1 and var2 each containing 8 bits from a certain source.

However I only need the 4 least significant bits from var1 and the 4 most significant bit from var 2 in order to fill up a new variable var3.

Any clue how to do this? (I need a command analogue to MOVFF but regarding moving single bits)

Thank you!
 
Engineering news on Phys.org
Magna Visus said:
Hello guys!

The following question is related to the P18F2520 series.

Suppose you have 2 defined variables var1 and var2 each containing 8 bits from a certain source.

However I only need the 4 least significant bits from var1 and the 4 most significant bit from var 2 in order to fill up a new variable var3.

Any clue how to do this? (I need a command analogue to MOVFF but regarding moving single bits)

Thank you!

Mask off the unwanted bits to 0 and then OR the two bytes...
 
Ah didn't think about using logical operators for this task. Thought that a movbit function exist.
Thanks for your answer I'll definitely use it!