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

using jb of a unsigned char in c

hello,
I would like to do a bit test of a unsigned char variable. It's like a jb in assembler.

here is my code in c.


unsigned char displ;
unsigned char display3 = 0xA8;
unsigned char i;
sbit display_data = P1^0;

displ = display3;
for (i=0; i<7; i++) {
        if (displ^0 == 1){
        display_data = 0;
        }
        else {
        display_data = 1;
        }
        displ>>=1;
}


I don't have any warning or error, but the result of test is wrong.
is it possible to do in c?

tkx.

Parents
  • "I detest the use of..."

    It is purely a matter of style - and such debates always produce strong opinions.

    Others would say that they detest the useless waste of a line with just a '{' on it, that it unnecessarily breaks up the code, etc, etc...

    "Is it just me that consider that style rendering the code unreadable?"

    I don't know about "unreadable", but I also dislike it.

    However, this style has extremely good credentials - it's what messrs Kernighan & Ritchie themselves use in their definitive work on the subject!

    c-faq.com/.../layout.html

Reply
  • "I detest the use of..."

    It is purely a matter of style - and such debates always produce strong opinions.

    Others would say that they detest the useless waste of a line with just a '{' on it, that it unnecessarily breaks up the code, etc, etc...

    "Is it just me that consider that style rendering the code unreadable?"

    I don't know about "unreadable", but I also dislike it.

    However, this style has extremely good credentials - it's what messrs Kernighan & Ritchie themselves use in their definitive work on the subject!

    c-faq.com/.../layout.html

Children
  • However, this style has extremely good credentials - it's what messrs Kernighan & Ritchie themselves use in their definitive work on the subject!

    I guess they did that to illustrate the lf/cr independence of C.

    so, this would be step one towards the 'ultimate' C program (the whole shebang in one line)

    OK, I agree that on matters of style everybody has a (different) opinion and the only reason I happened to bring it up was that this particular 'style' threw me off a bit in this case. I appreciate getting one 'yes' (makes me feel not crazy [in this respect]) and let us leave it at that.

    Erik

    PS re 'conserving linespace' I often do this
    if (blah)
    { // since blah is set .....

  • "PS re 'conserving linespace' I often do this
    if (blah)
    { // since blah is set ....."

    Yes - so do I!

    The comment aligns with the indented text:

    if( condition )
    {   // Condition is true - time to do stuff
        do_stuff();
        do_other_stuff();
        etc();
    }