{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Chapter 7: Logic circuits" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 7.1: example_1.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "clc\n", "//ex7.1\n", "N=343; //decimal integer\n", "N2=dec2bin(N); //binary equivalent of N\n", "disp(N2,'Binary equivalent of 343 is')" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 7.2: example_2.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "clc\n", "//ex7.2\n", "N=0.392; //decimal\n", "DP=N; //decimal part(no integer part)\n", "i=1;\n", "x=1;\n", "//Each decimal digit is stored in D(x)\n", "while (x<=9)\n", "DP=DP*2;\n", "D(x)= floor (DP);\n", "x=x+1;\n", "DP= modulo (DP ,1);\n", "end\n", "DP=0;\n", "for j=1: length (D)\n", "//bits of decimal part are multiplied with their position values and adding them\n", " DP=DP+(10^(-1*j)*D(j));\n", "end\n", "disp(DP,'Binary form of 0.392 is')" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 7.3: example_3.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "clc\n", "//ex7.3\n", "N=343.392;\n", "//convert the integer and decimal parts into binary form separately\n", "B_1='101010111'; //for 343 from ex7.1\n", "B_2='0.011001'; //for 0.392 from ex7.2\n", "//combining these two\n", "B='101010111.011001'; //for N, given number\n", "disp(B,'binary form of 343.392')" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 7.4: example_4.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "//ex7.4\n", "N_1=1000.111;\n", "N_2=1100.011;\n", "//Adding these two according to the rules of binary addition in fig7.6, we get\n", "disp('The result of addition of given two binary numbers is')\n", "disp('10101.010')" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 7.5: example_5.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "clc\n", "//ex7.5\n", "//Given 317.2 (octal)and F3A.2 (hexadecimal)\n", "//From table 7.1 in text, corresponding octal forms of 3,1,7 and 2 are 011,001,111 and 010\n", "disp('The binary representation of 317.2(octal) is ')\n", "disp('011001111.010')\n", "disp('')\n", "//From table 7.1 in text, corresponding hexadecimal forms of F,3,A and 2 are 1111,0011,1010 and 0010\n", "disp('The binary representation of F3A.2(hexadecimal) is ')\n", "disp('111100111010.0010')" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 7.6: example_6.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "clc\n", "//ex7.6\n", "//Given 11110110.1(binary)\n", "//Working outward from the binary point, we form three-bit groups ==> 11110110.1=011 110 110. 100(we have appended leading and trailing zeros so that each group contains 3 bits)\n", "//And the corresponding numbers for 011,110,110 and 100 in octal system are 3,6,6 and 4\n", "disp('The octal representation of 11110110.1(binary) is 366.4')\n", "//Now we form four-bit groups appending leading and trailing zeros as needed ==> 11110110.1=1111 0110. 1000\n", "//The corresponding numbers for 1111,0110 and 1000 in hexadecimal system are F,6 and 8\n", "disp('The hexadecimal representation of 11110110.1(binary) is F6.8')" ] } ], "metadata": { "kernelspec": { "display_name": "Scilab", "language": "scilab", "name": "scilab" }, "language_info": { "file_extension": ".sce", "help_links": [ { "text": "MetaKernel Magics", "url": "https://github.com/calysto/metakernel/blob/master/metakernel/magics/README.md" } ], "mimetype": "text/x-octave", "name": "scilab", "version": "0.7.1" } }, "nbformat": 4, "nbformat_minor": 0 }