From b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b Mon Sep 17 00:00:00 2001 From: priyanka Date: Wed, 24 Jun 2015 15:03:17 +0530 Subject: initial commit / add all books --- 1964/CH15/EX15.10/ex15_10.sce | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 1964/CH15/EX15.10/ex15_10.sce (limited to '1964/CH15/EX15.10/ex15_10.sce') diff --git a/1964/CH15/EX15.10/ex15_10.sce b/1964/CH15/EX15.10/ex15_10.sce new file mode 100755 index 000000000..fad908300 --- /dev/null +++ b/1964/CH15/EX15.10/ex15_10.sce @@ -0,0 +1,21 @@ +//Chapter-15, Example 15.10, Page 497 +//============================================================================= +clc +clear +//CALCULATIONS +//using 1's complement method +x1=base2dec(['1000'],2)//converting binary to decimal +x=bin2dec('1010') +x2=dec2bin(bitcmp(x,4))//1's complement of a number +disp(x2) +x3=base2dec([x2],2) +x4=x1+x3+1; +x5=dec2base(x4,2)//converting decimal to hexadecimal +disp(x5) +//using normal method +a=base2dec(['1000','1010'],2);//converting binary to decimal +b=a(2)-a(1);//subtraction +c=dec2base(b,2)//converting decimal to binary +disp(c) +//since we cannot use dec2base for negative integers,we cannot do (a(1)-a(2)) but we can do (a(2)-a(1)),with '-' sign added before the result.hence 'c' here is actually -'c' +//=================================END OF PROGRAM======================================================================================================= -- cgit