Skip navigation

This solution is for the book I am currently reading. All of my notes and solutions are available at Google Code.

Here is my work for problem 2.13:

Suppose that x and y have byte values 0x66 and 0x93, respectively. Fill in the
following table indicating the byte values of the different C expressions:

Expression  Value  Expression   Value
-------------------------------------
  x & y              x && y
-------------------------------------
  x | y              x || y
-------------------------------------
 ~x | ~y            !x || !y
-------------------------------------
  x | !y             x && ~y
-------------------------------------


x & y

    0x66
 &  0x93
 -------

   01100110
 & 10010011
 ----------
   00000010

   0x02

x && y = 0x01

x | y

    0x66
 |  0x93
 -------

   01100110
 | 10010011
 ----------
   11110111

   0xF7

x || y = 0x01

~x | ~y

    ~0x66
 |  ~0x93
 --------

   ~01100110
 | ~10010011
 -----------

   10011001
 | 01101100
 ----------
   11111101

   0xFD

!x || !y = 0x00

x & !y

    0x66
 &  0x01
 -------

   01100110
 & 00000001
 ----------
   00000000

   0x00

 x && ~y

      0x66
 &&  ~0x93
 ---------

      0x66
 &&  ~0x93
 ---------

     01100110
 && ~10010011
 ------------


    01100110
 && 01101100
 -----------

      0x66
 &&   0x6C
 ---------
      0x01


Expression  Value  Expression   Value
-------------------------------------
  x & y      0x02    x && y      0x01
-------------------------------------
  x | y      0xF7    x || y      0x01
-------------------------------------
 ~x | ~y     0xFD    !x || !y    0x00
-------------------------------------
  x | !y     0x00     x && ~y    0x01
-------------------------------------

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: