summaryrefslogtreecommitdiff
path: root/Practical_C_Programming/Chapter_11_1.ipynb
blob: 348ea0f2f6bf6284b4c7a48fdbcf3eb80c23393f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
{
 "metadata": {
  "name": "",
  "signature": "sha256:189fb021544012d2bd6866a28aeac9bea1998c8f59c87bf7f6fbc3d56515bb70"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 11: Bit operations"
     ]
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 11.1, Page number: 193"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "i1 = 4\n",
      "i2 = 2\n",
      "\n",
      "# Calculation and result\n",
      "if ((i1 != 0) and (i2 != 0)) :\n",
      "   print ('Both are not zero\\n')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Both are not zero\n",
        "\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 11.2, Page number: 201"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "HIGH_SPEED = 1 << 7\n",
      "DIRECT_CONNECT = 1 << 8\n",
      "\n",
      "flags = 0\n",
      "flags |= HIGH_SPEED\n",
      "flags |= DIRECT_CONNECT\n",
      "\n",
      "# Calculation and result\n",
      "if ((flags & HIGH_SPEED) != 0) :\n",
      "   print ('High speed set\\n')\n",
      "\n",
      "if ((flags & DIRECT_CONNECT) != 0) :\n",
      "   print ('Direct connect set\\n')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "High speed set\n",
        "\n",
        "Direct connect set\n",
        "\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 11.4, Page number: 207"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "i = 0x80\n",
      "\n",
      "# Calculation and result\n",
      "if (i != 0) :\n",
      "   print ('i is %x (%d) \\n' % (i, i))\n",
      "   i = i >> 1"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "i is 80 (128) \n",
        "\n"
       ]
      }
     ],
     "prompt_number": 3
    }
   ],
   "metadata": {}
  }
 ]
}