{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 10 - Combinational Logic Systems"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 10_1 Page No.  308"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Decimal number= 72\n",
      "Eqivalent Binary number= 1001000\n"
     ]
    }
   ],
   "source": [
    "x=72##given value in Decimal\n",
    "print \"Decimal number=\",(x)\n",
    "Str=bin(x)[2:]\n",
    "print \"Eqivalent Binary number=\",(Str)#Binary value"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 10_2 Page No.  308"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Binary number= 1001000\n",
      "Eqivalent Decimal number= 72\n"
     ]
    }
   ],
   "source": [
    "x='1001000'##Binary value\n",
    "print \"Binary number=\",(x)\n",
    "Str=int(x,2)\n",
    "print \"Eqivalent Decimal number=\",(Str)#decimal value"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 10_3 Page No.  308"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Binary number= 1001000\n",
      "Eqivalent Octal number= 0110\n"
     ]
    }
   ],
   "source": [
    "b='1001000'#\n",
    "print \"Binary number=\",(b)#Binary value\n",
    "d=int(b,2)# Binary to decimal value\n",
    "o=oct(d)# Decimal to octal\n",
    "print \"Eqivalent Octal number=\",(o)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 10_4 Page No.  309"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Decimal number= 72\n",
      "Eqivalent Octal number= 0110\n"
     ]
    }
   ],
   "source": [
    "x=72#\n",
    "print \"Decimal number=\",(x)#Decimal value\n",
    "Str=oct(x)#decimal to octal\n",
    "print \"Eqivalent Octal number=\",(Str)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 10_5 Page No.  309"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Octal number= 110\n",
      "Eqivalent Binary number= 1001000\n"
     ]
    }
   ],
   "source": [
    "x='110'#\n",
    "print \"Octal number=\",(x)#octal value\n",
    "y=int(x,8)# octal to decimal\n",
    "Str=bin(y)[2:] #decimal to binary\n",
    "print \"Eqivalent Binary number=\",(Str)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 10_6 Page No.  309"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Octal number= 110\n",
      "Eqivalent Decimal number= 72\n"
     ]
    }
   ],
   "source": [
    "x='110'#\n",
    "print \"Octal number=\",(x)# octal value\n",
    "Str=int(x,8)#octal to decimal\n",
    "print \"Eqivalent Decimal number=\",(Str)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 10_7 Page No.  309"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Decimal number= 72\n",
      "Eqivalent Hexadecimal number= 48\n"
     ]
    }
   ],
   "source": [
    "x=72#\n",
    "print \"Decimal number=\",(x) #decimal value\n",
    "Str=hex(x)[2:]# decimal to hexadecimal\n",
    "print \"Eqivalent Hexadecimal number=\",(Str)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 10_8 Page No.  310"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hexadecimal number= 48\n",
      "Eqivalent Decimal number= 72\n"
     ]
    }
   ],
   "source": [
    "h='48'#\n",
    "print \"Hexadecimal number=\",(h)# value in hexadecimal\n",
    "d=int(h,16)#hexadecimal to decimal\n",
    "print \"Eqivalent Decimal number=\",(d)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 10_9 Page No.  310"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hexadecimal number= 48\n",
      "Eqivalent Binary number= 1001000\n"
     ]
    }
   ],
   "source": [
    "h='48'#\n",
    "print \"Hexadecimal number=\",(h) #hexadecimal\n",
    "d=int(h,16)# converting hexadecimal to decimal\n",
    "Str=bin(d)[2:]# converting decimal to binary\n",
    "print \"Eqivalent Binary number=\",(Str)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 10_10 Page No.  310"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Binary number= 1001000\n",
      "Eqivalent hexadecimal number= 48\n"
     ]
    }
   ],
   "source": [
    "x='1001000'#\n",
    "print \"Binary number=\",(x)#binary value\n",
    "d=int(x,2)#binary to decimal\n",
    "h=hex(d)[2:] #decimal to hexa decimal\n",
    "print \"Eqivalent hexadecimal number=\",(h)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 10_11 Page No.  311"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Eqivalent BCD of 72 =  111010\n"
     ]
    }
   ],
   "source": [
    "#for two digit decimal value to convert into BCD\n",
    "#for two digit decimal value to convert into BCD\n",
    "x='72'#\n",
    "digits = [int(c) for c in x]\n",
    "zero_padded_BCD_digits = [format(d, '03b') for d in digits]\n",
    "print \"Eqivalent BCD of 72 = \",\n",
    "print ''.join(zero_padded_BCD_digits)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}