EmbLogic's Blog

today update 8/6/12. Problem in bitwise OR

i had complete assignment qs up to 11.

int x=1;
printf(“\n %d”,~x|x);

output : -1

2 Responses to today update 8/6/12. Problem in bitwise OR

  1. msiddarth says:

    The program will be evaluated in this form: ((~x) | x)
    i.e. In step1 the complement of X will become
    11…..10
    and also the value of x will not be updated with the same complement value hence
    11…..10
    | 00…..01
    ————–
    11…..11
    —————
    and the value of 111….11 is -1 in two’s complement compiler.
    Hence we are getting the value as -1

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>