This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Logic Operators

Hi, I need help understanding these operations


DEECON=(unsigned char)((adr>>8)&0x01);
is adr being shifted to the right? and then?
what is &0x01 ...a pointer?


while((DEECON&0x80)==0);
Explain the logic operation here please.

The more detail the better...I am new at this
Thank you

Parents
  • I suggest you obtain a C programming language textbook. Here's an on-line reference:

    http://www-ccs.ucsd.edu/c/

    but it doesn't have a great deal of tutorial information.


    >DEECON=(unsigned char)((adr>>8)&0x01);
    >is adr being shifted to the right?

    Yes, by 8 bits.

    >and then? what is &0x01 ...a pointer?

    It's the bitwise AND operator '&', followed by a literal integer constant in base 16 (hexadecimal).

    The spacing here is bad; conventional style puts whitespace around the bitwise operator, while address-of operator '&' is directly adjacent to the variable. There's no such thing as the address of a literal in C, which is the other way you know what they meant.

    The net effect is to obtain the low bit of the high byte of adr - shift right, and mask all but the low-order bit.

    >while((DEECON&0x80)==0);
    >Explain the logic operation here please.

    Note the semicolon at the end of the statement. (Bad style, IMO). There is no body to this for loop.

    While the condition is true, this statement will loop. The condition is checking the high bit of DEECON. When it becomes 1, the comparison with zero will fail, and program execution will proceed past the while loop. In other words, wait until bit 7 in DEECON goes high.

    DEECON is presumably declared elsewhere as some register in hardware that will change on its own. What the high order bit might be is a question best answered by the appropriate data sheet.

    >The more detail the better...I am new at this

    You're going to need to study the programming language if you want to use it effectively.

Reply
  • I suggest you obtain a C programming language textbook. Here's an on-line reference:

    http://www-ccs.ucsd.edu/c/

    but it doesn't have a great deal of tutorial information.


    >DEECON=(unsigned char)((adr>>8)&0x01);
    >is adr being shifted to the right?

    Yes, by 8 bits.

    >and then? what is &0x01 ...a pointer?

    It's the bitwise AND operator '&', followed by a literal integer constant in base 16 (hexadecimal).

    The spacing here is bad; conventional style puts whitespace around the bitwise operator, while address-of operator '&' is directly adjacent to the variable. There's no such thing as the address of a literal in C, which is the other way you know what they meant.

    The net effect is to obtain the low bit of the high byte of adr - shift right, and mask all but the low-order bit.

    >while((DEECON&0x80)==0);
    >Explain the logic operation here please.

    Note the semicolon at the end of the statement. (Bad style, IMO). There is no body to this for loop.

    While the condition is true, this statement will loop. The condition is checking the high bit of DEECON. When it becomes 1, the comparison with zero will fail, and program execution will proceed past the while loop. In other words, wait until bit 7 in DEECON goes high.

    DEECON is presumably declared elsewhere as some register in hardware that will change on its own. What the high order bit might be is a question best answered by the appropriate data sheet.

    >The more detail the better...I am new at this

    You're going to need to study the programming language if you want to use it effectively.

Children
No data