0
\$\begingroup\$

I am now learning avr programming using c. I have a problem with bitshifting. Suppose I have a 8 bit register named jcb containing 01110011. I want to get the upper 4 bits in vh variable. So, I do vh = (jcb >> 4). Now the value of vh must be 0111. But if now I do vl = jcb , what is the binary value containing in vl in 8 bit?

| improve this question | | | | |
\$\endgroup\$
  • \$\begingroup\$ vl=vcb, can't be different. \$\endgroup\$ – Marko Buršič Aug 28 '18 at 20:01
4
\$\begingroup\$

01110011 again, since you didn't do anything to change jcb, such as jcb = jcb>>4;

If you wanted the lower 4 bits of jcb in vl, then mask the upper 4 bits off.

vl = 0x0F & jcb; // upper 4 bits = 0, lower 4 bits = 0011

| improve this answer | | | | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.