{ "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": {} } ] }