summaryrefslogtreecommitdiff
path: root/Practical_C_Programming/Chapter_11_1.ipynb
blob: e3193adbbffdb200474295962f9fd4a4e05e82ac (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
{
 "metadata": {
  "name": "Chapter 11"
 },
 "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": "# Example 11.1.py\n# To check whether two numbers are equal to 0 or not\n\n\n# Variable declaration\ni1 = 4\ni2 = 2\n\n# Calculation and result\nif ((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": "# Example 11.2.py\n# To illustrate the use of bitwise and shift operators\n\n\n# Variable declaration\nHIGH_SPEED = 1 << 7\nDIRECT_CONNECT = 1 << 8\n\nflags = 0\nflags |= HIGH_SPEED\nflags |= DIRECT_CONNECT\n\n# Calculation and result\nif ((flags & HIGH_SPEED) != 0) :\n   print ('High speed set\\n')\n\nif ((flags & DIRECT_CONNECT) != 0) :\n   print ('Direct connect set\\n')",
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": "High speed set\n\nDirect 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": "# Example 11.4.py\n# To test a loop counter\n\n\n# Variable declaration\ni = 0x80\n\n# Calculation and result\nif (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": {}
  }
 ]
}