diff options
Diffstat (limited to '243/CH3')
-rwxr-xr-x | 243/CH3/EX3.1/3_01.sce | 22 | ||||
-rwxr-xr-x | 243/CH3/EX3.10/3_10.sce | 29 | ||||
-rwxr-xr-x | 243/CH3/EX3.11/3_11.sce | 11 | ||||
-rwxr-xr-x | 243/CH3/EX3.12/3_12.sce | 13 | ||||
-rwxr-xr-x | 243/CH3/EX3.13/3_13.sce | 28 | ||||
-rwxr-xr-x | 243/CH3/EX3.14/3_14.sce | 28 | ||||
-rwxr-xr-x | 243/CH3/EX3.15/3_15.sce | 21 | ||||
-rwxr-xr-x | 243/CH3/EX3.16/3_16.sce | 17 | ||||
-rwxr-xr-x | 243/CH3/EX3.17/3_17.sce | 18 | ||||
-rwxr-xr-x | 243/CH3/EX3.18/3_18.sce | 28 | ||||
-rwxr-xr-x | 243/CH3/EX3.19/3_19.sce | 17 | ||||
-rwxr-xr-x | 243/CH3/EX3.2/3_02.sce | 17 | ||||
-rwxr-xr-x | 243/CH3/EX3.20/3_20.sce | 18 | ||||
-rwxr-xr-x | 243/CH3/EX3.21/3_21.sce | 20 | ||||
-rwxr-xr-x | 243/CH3/EX3.22/3_22.sce | 67 | ||||
-rwxr-xr-x | 243/CH3/EX3.23/3_23.sce | 10 | ||||
-rwxr-xr-x | 243/CH3/EX3.24/3_24.sce | 37 | ||||
-rwxr-xr-x | 243/CH3/EX3.3/3_03.sce | 25 | ||||
-rwxr-xr-x | 243/CH3/EX3.4/3_04.sce | 8 | ||||
-rwxr-xr-x | 243/CH3/EX3.5/3_05.sce | 33 | ||||
-rwxr-xr-x | 243/CH3/EX3.6/3_06.sce | 31 | ||||
-rwxr-xr-x | 243/CH3/EX3.7/3_07.sce | 40 | ||||
-rwxr-xr-x | 243/CH3/EX3.8/3_08.sce | 14 | ||||
-rwxr-xr-x | 243/CH3/EX3.9/3_09.sce | 28 |
24 files changed, 580 insertions, 0 deletions
diff --git a/243/CH3/EX3.1/3_01.sce b/243/CH3/EX3.1/3_01.sce new file mode 100755 index 000000000..0e2e7143f --- /dev/null +++ b/243/CH3/EX3.1/3_01.sce @@ -0,0 +1,22 @@ +//Example No. 3_01
+//Binary to decimal
+//Pg No. 45
+clear ;close ; clc ;
+
+b = '1101.1101'
+v = strsplit(b,'.') //splitting integral part and fraction part
+integralp = str2code(v(1))//converting strings to numbers
+fractionp = str2code(v(2))
+li = length(integralp) //lenght of integral part
+lf = length(fractionp) // and fractional part
+di = 0 ;//Initializing integral part and decimal part
+df = 0 ;
+for i = 1:li
+ di = 2*di+integralp(i)
+end
+for i = lf:-1:1
+ df = df/2 + fractionp(i)
+end
+df = df/2 ;
+d = di + df ; //Integral and fractional parts
+disp(d,'Decimal value = ')
\ No newline at end of file diff --git a/243/CH3/EX3.10/3_10.sce b/243/CH3/EX3.10/3_10.sce new file mode 100755 index 000000000..a00aa0d85 --- /dev/null +++ b/243/CH3/EX3.10/3_10.sce @@ -0,0 +1,29 @@ +//Example No. 3_10
+//Floating Point Notation
+//Pg No. 52
+clear ; close ; clc ;
+
+function [m,e] =float_notation(n)
+m = n ;
+for i = 1:16
+ if abs(m) >= 1 then
+ m = n/10^i
+ e = i
+ elseif abs(m) < 0.1
+ m = n*10^i
+ e = -i
+ else
+ if i == 1 then
+ e = 0
+ end
+ break ;
+ end
+end
+endfunction
+
+[m,e] = float_notation(0.00596)
+mprintf('\n 0.00596 is expressed as %f*10^%i \n',m,e)
+[m,e] = float_notation(65.7452)
+mprintf('\n 65.7452 is expressed as %f*10^%i \n',m,e)
+[m,e] = float_notation(-486.8)
+mprintf('\n -486.8 is expressed as %f*10^%i \n',m,e)
\ No newline at end of file diff --git a/243/CH3/EX3.11/3_11.sce b/243/CH3/EX3.11/3_11.sce new file mode 100755 index 000000000..9dc16d29e --- /dev/null +++ b/243/CH3/EX3.11/3_11.sce @@ -0,0 +1,11 @@ +//Example No. 3_11
+//Interger Arithmetic
+//Pg No. 53
+clear ;close ;clc ;
+
+disp(int(25 + 12))
+disp(int(25 - 12))
+disp(int(12 - 25))
+disp(int(25*12))
+disp(int(25/12))
+disp(int(12/25))
\ No newline at end of file diff --git a/243/CH3/EX3.12/3_12.sce b/243/CH3/EX3.12/3_12.sce new file mode 100755 index 000000000..34f905129 --- /dev/null +++ b/243/CH3/EX3.12/3_12.sce @@ -0,0 +1,13 @@ +//Example No. 3_12
+//Integer Arithmetic
+//Pg No. 53
+clear ;close ;clc ;
+a = 5 ;
+b = 7 ;
+c = 3 ;
+Lhs = int((a + b)/c)
+Rhs = int(a/c) + int(b/c)
+disp(Rhs,'a/c + b/c = ',Lhs,'(a+b)/c = ')
+if Lhs ~= Rhs then
+ disp('The results are not identical.This is because the remainder of an integer division is always truncated')
+end
\ No newline at end of file diff --git a/243/CH3/EX3.13/3_13.sce b/243/CH3/EX3.13/3_13.sce new file mode 100755 index 000000000..8ef53066d --- /dev/null +++ b/243/CH3/EX3.13/3_13.sce @@ -0,0 +1,28 @@ +//Example No. 3_13
+//Floating Point Arithmetic
+//Pg No. 54
+clear ;close ;clc ;
+
+fx = 0.586351 ;
+Ex = 5 ;
+fy = 0.964572 ;
+Ey = 2 ;
+[Ez,n] = max(Ex,Ey)
+if n == 1 then
+ fy = fy*10^(Ey-Ex)
+ fz = fx + fy
+ if fz > 1 then
+ fz = fz*10^(-1)
+ Ez = Ez + 1
+ end
+ disp(fz,'fz = ',fy,'fy = ',Ez,'Ez = ')
+else
+ fx = fx*10^(Ex - Ey)
+ fz = fx + fy
+ if fz > 1 then
+ fz = fz*10^(-1)
+ Ez = Ez + 1
+ end
+ disp(fz,'fz = ',fx,'fx = ',Ez,'Ez = ')
+end
+mprintf('\n z = %f E%i \n',fz,Ez)
\ No newline at end of file diff --git a/243/CH3/EX3.14/3_14.sce b/243/CH3/EX3.14/3_14.sce new file mode 100755 index 000000000..670d00cba --- /dev/null +++ b/243/CH3/EX3.14/3_14.sce @@ -0,0 +1,28 @@ +//Example No. 3_14
+//Floating Point Arithmetic
+//Pg No. 54
+clear ;close ;clc ;
+
+fx = 0.735816 ;
+Ex = 4 ;
+fy = 0.635742 ;
+Ey = 4 ;
+[Ez,n] = max(Ex,Ey)
+if n == 1 then
+ fy = fy*10^(Ey-Ex)
+ fz = fx + fy
+ if fz > 1 then
+ fz = fz*10^(-1)
+ Ez = Ez + 1
+ end
+ disp(fz,'fz = ',fy,'fy = ',Ez,'Ez = ')
+else
+ fx = fx*10^(Ex - Ey)
+ fz = fx + fy
+ if fz > 1 then
+ fz = fz*10^(-1)
+ Ez = Ez + 1
+ end
+ disp(fz,'fz = ',fx,'fx = ',Ez,'Ez = ')
+end
+mprintf('\n z = %f E%i \n',fz,Ez)
\ No newline at end of file diff --git a/243/CH3/EX3.15/3_15.sce b/243/CH3/EX3.15/3_15.sce new file mode 100755 index 000000000..ce894febf --- /dev/null +++ b/243/CH3/EX3.15/3_15.sce @@ -0,0 +1,21 @@ +//Example No. 3_15
+//Floating Point Arithmetic
+//Pg No. 54
+clear ;close ;clc ;
+
+fx = 0.999658 ;
+Ex = -3 ;
+fy = 0.994576 ;
+Ey = -3 ;
+Ez = max(Ex,Ey)
+fy = fy*10^(Ey-Ex)
+fz = fx - fy
+disp(fz,'fz = ',Ez,'Ez = ')
+mprintf('\n z = %f E%i \n',fz,Ez)
+if fz < 0.1 then
+ fz = fz*10^6 //Since we are using 6 significant digits
+ n = length(string(fz))
+ fz = fz/10^n
+ Ez = Ez + n - 6
+ mprintf('\n z = %f E%i (normalised) \n',fz,Ez)
+end
\ No newline at end of file diff --git a/243/CH3/EX3.16/3_16.sce b/243/CH3/EX3.16/3_16.sce new file mode 100755 index 000000000..638f52d65 --- /dev/null +++ b/243/CH3/EX3.16/3_16.sce @@ -0,0 +1,17 @@ +//Example No. 3_16
+//Floating Point Arithmetic
+//Pg No. 55
+clear ;close ;clc ;
+
+fx = 0.200000 ;
+Ex = 4 ;
+fy = 0.400000 ;
+Ey = -2 ;
+fz = fx*fy
+Ez = Ex + Ey
+mprintf('\n fz = %f \n Ez = %i \n z = %f E%i \n',fz,Ez,fz,Ez)
+if fz < 0.1 then
+ fz = fz*10
+ Ez = Ez - 1
+ mprintf('\n z = %f E%i (normalised) \n',fz,Ez)
+end
\ No newline at end of file diff --git a/243/CH3/EX3.17/3_17.sce b/243/CH3/EX3.17/3_17.sce new file mode 100755 index 000000000..9c60d7499 --- /dev/null +++ b/243/CH3/EX3.17/3_17.sce @@ -0,0 +1,18 @@ +//Example No. 3_17
+//Floating Point Arithmetic
+//Pg No. 55
+clear ;close ;clc ;
+
+fx = 0.876543 ;
+Ex = -5 ;
+fy = 0.200000 ;
+Ey = -3 ;
+fz = fx/fy
+Ez = Ex - Ey
+mprintf('\n fz = %f \n Ez = %i \n z = %f E%i \n',fz,Ez,fz,Ez)
+
+if fz > 1 then
+ fz = fz/10
+ Ez = Ez + 1
+ mprintf('\n z = %f E%i (normalised) \n',fz,Ez)
+end
\ No newline at end of file diff --git a/243/CH3/EX3.18/3_18.sce b/243/CH3/EX3.18/3_18.sce new file mode 100755 index 000000000..b5b1a3773 --- /dev/null +++ b/243/CH3/EX3.18/3_18.sce @@ -0,0 +1,28 @@ +//Example No. 3_18
+//Floating Point Arithmetic
+//Pg No. 56
+clear ;close ;clc ;
+
+fx = 0.500000 ;
+Ex = 1 ;
+fy = 0.100000 ;
+Ey = -7 ;
+[Ez,n] = max(Ex,Ey)
+if n == 1 then
+ fy = fy*10^(Ey-Ex)
+ fz = fx + fy
+ if fz > 1 then
+ fz = fz*10^(-1)
+ Ez = Ez + 1
+ end
+ disp(fy,'fy = ',Ez,'Ez = ')
+else
+ fx = fx*10^(Ex - Ey)
+ fz = fx + fy
+ if fz > 1 then
+ fz = fz*10^(-1)
+ Ez = Ez + 1
+ end
+ disp(fx,'fx = ',Ez,'Ez = ')
+end
+mprintf('\n fz = %f \n z = %f E%i \n',fz,fz,Ez)
\ No newline at end of file diff --git a/243/CH3/EX3.19/3_19.sce b/243/CH3/EX3.19/3_19.sce new file mode 100755 index 000000000..e8b2a38f4 --- /dev/null +++ b/243/CH3/EX3.19/3_19.sce @@ -0,0 +1,17 @@ +//Example No. 3_19
+//Floating Point Arithmetic
+//Pg No. 56
+clear ;close ;clc ;
+
+fx = 0.350000 ;
+Ex = 40 ;
+fy = 0.500000 ;
+Ey = 70 ;
+fz = fx*fy
+Ez = Ex + Ey
+mprintf('\n fz = %f \n Ez = %i \n z = %f E%i \n',fz,Ez,fz,Ez)
+if fz < 0.1 then
+ fz = fz*10
+ Ez = Ez - 1
+ mprintf('\n z = %f E%i (normalised) \n',fz,Ez)
+end
\ No newline at end of file diff --git a/243/CH3/EX3.2/3_02.sce b/243/CH3/EX3.2/3_02.sce new file mode 100755 index 000000000..43a501ad4 --- /dev/null +++ b/243/CH3/EX3.2/3_02.sce @@ -0,0 +1,17 @@ +//Example No. 3_02
+//hexadecimal to decimal
+//Pg No. 46
+clear ; close ; clc ;
+
+h = '12AF' ;
+u = str2code(h)
+u = abs(u)
+n = length(u)
+d = 0
+for i = 1:n
+ d = d*16 + u(i)
+end
+disp(d,'Decimal value = ')
+//Using Scilab Function
+d = hex2dec(h)
+disp(d,'Using scilab function Decimal value = ')
\ No newline at end of file diff --git a/243/CH3/EX3.20/3_20.sce b/243/CH3/EX3.20/3_20.sce new file mode 100755 index 000000000..6496ad36d --- /dev/null +++ b/243/CH3/EX3.20/3_20.sce @@ -0,0 +1,18 @@ +//Example No. 3_20
+//Floating Point Arithmetic
+//Pg No. 56
+clear ;close ;clc ;
+
+fx = 0.875000 ;
+Ex = -18 ;
+fy = 0.200000 ;
+Ey = 95 ;
+fz = fx/fy
+Ez = Ex - Ey
+mprintf('\n fz = %f \n Ez = %i \n z = %f E%i \n',fz,Ez,fz,Ez)
+
+if fz > 1 then
+ fz = fz/10
+ Ez = Ez + 1
+ mprintf('\n z = %f E%i (normalised) \n',fz,Ez)
+end
\ No newline at end of file diff --git a/243/CH3/EX3.21/3_21.sce b/243/CH3/EX3.21/3_21.sce new file mode 100755 index 000000000..9d0f1f7b2 --- /dev/null +++ b/243/CH3/EX3.21/3_21.sce @@ -0,0 +1,20 @@ +//Example No. 3_21
+//Floating Point Arithmetic
+//Pg No. 57
+clear ;close ;clc ;
+
+fx = 0.500000 ;
+Ex = 0 ;
+fy = 0.499998 ;
+Ey = 0 ;
+Ez = 0 ;
+fz = fx - fy
+disp(fz,'fz = ',Ez,'Ez = ')
+mprintf('\n z = %f E%i \n',fz,Ez)
+if fz < 0.1 then
+ fz = fz*10^6
+ n = length(string(fz))
+ fz = fz/10^n
+ Ez = Ez + n - 6
+ mprintf('\n z = %f E%i (normalised) \n',fz,Ez)
+end
\ No newline at end of file diff --git a/243/CH3/EX3.22/3_22.sce b/243/CH3/EX3.22/3_22.sce new file mode 100755 index 000000000..c687feebd --- /dev/null +++ b/243/CH3/EX3.22/3_22.sce @@ -0,0 +1,67 @@ +//Example No. 3_22
+//Laws of Arithmetic
+//Pg No. 57
+clear ; close ; clc ;
+function [fz,Ez] =add_sub(fx,Ex,fy,Ey) //addition and subtraction fuction
+if fx*fy >= 0 then
+ //Addition
+ [Ez,n] = max(Ex,Ey)
+ if n == 1 then
+ fy = fy*10^(Ey-Ex)
+ fz = fx + fy
+ if fz > 1 then
+ fz = fz*10^(-1)
+ Ez = Ez + 1
+ end
+ else
+ fx = fx*10^(Ex - Ey)
+ fz = fx + fy
+ if fz > 1 then
+ fz = fz*10^(-1)
+ Ez = Ez + 1
+ end
+ end
+
+else
+ //Subtraction
+ [Ez,n] = max(Ex,Ey)
+ if n == 1 then
+ fy = fy*10^(Ey-Ex)
+ fz = fx + fy
+ if abs(fz) < 0.1 then
+ fz = fz*10^6
+ fz = floor(fz)
+ nfz = length(string(abs(fz)))
+ fz = fz/10^nfz
+ Ez = nfz - 6
+ end
+ else
+ fx = fx*10^(Ex - Ey)
+ fz = fx + fy
+ if fz < 0.1 then
+ fz = fz*10^6
+ fz = int(fz)
+ nfz = length(string(abs(fz)))
+ fz = fz/10^nfz
+ Ez = nfz - 6
+ end
+ end
+end
+endfunction
+
+fx = 0.456732
+Ex = -2
+fy = 0.243451
+Ey = 0
+fz = -0.24800
+Ez = 0
+
+[fxy,Exy] = add_sub(fx,Ex,fy,Ey)
+[fxy_z,Exy_z] = add_sub(fxy,Exy,fz,Ez)
+[fyz,Eyz] = add_sub(fy,Ey,fz,Ez)
+[fx_yz,Ex_yz] = add_sub(fx,Ex,fyz,Eyz)
+mprintf('fxy = %f\n Exy = %i \n fxy_z = %f\n Exy_z = %i \n fyz = %f \n Eyz = %i \n fx_yz = %f \n Ex_yz = %i \n',fxy,Exy,fxy_z,Exy_z,fyz,Eyz,fx_yz,Ex_yz)
+
+if fxy_z ~= fx_yz | Exy_z ~= Ex_yz then
+ disp('(x+y) + z ~= x + (y+z)')
+end
\ No newline at end of file diff --git a/243/CH3/EX3.23/3_23.sce b/243/CH3/EX3.23/3_23.sce new file mode 100755 index 000000000..50d9630c0 --- /dev/null +++ b/243/CH3/EX3.23/3_23.sce @@ -0,0 +1,10 @@ +//Example No. 3_23
+//Associative law
+//Pg No. 58
+clear ; close ; clc ;
+x = 0.400000*10^40
+y = 0.500000*10^70
+z = 0.300000*10^(-30)
+disp('In book they have considered the maximum exponent can be only 99, since 110 is greater than 99 the result is erroneous')
+disp((x*y)*z,'xy_z = ','but in scilab the this value is much larger than 110 so we get a correct result ')
+disp(x*(y*z),'x_yz = ')
\ No newline at end of file diff --git a/243/CH3/EX3.24/3_24.sce b/243/CH3/EX3.24/3_24.sce new file mode 100755 index 000000000..b43ecbe0c --- /dev/null +++ b/243/CH3/EX3.24/3_24.sce @@ -0,0 +1,37 @@ +//Example No. 3_24
+//Distributive law
+//Pg No. 58
+clear ;close ;clc ;
+
+x = 0.400000*10^1 ;
+fx = 0.400000
+Ex = 1
+y = 0.200001*10^0 ;
+z = 0.200000*10^0 ;
+x_yz = x*(y-z)
+x_yz = x_yz*10^6
+x_yz = floor(x_yz) //considering only six significant digits
+n = length(string(x_yz))
+fx_yz = x_yz/10^n
+Ex_yz = n - 6
+x_yz = fx_yz *10^Ex_yz
+disp(x_yz,'x_yz = ')
+
+fxy = fx*y
+fxy = fxy*10^6
+fxy = floor(fxy) //considering only six significant digits
+n = length(string(fxy))
+fxy = fxy/10^n
+Exy = n - 6
+xy = fxy * 10^Exy
+
+fxz = fx*z
+fxz = fxz*10^6
+fxz = floor(fxz) //considering only six significant digits
+n = length(string(fxz))
+fxz = fxz/10^n
+Exz = n - 6
+xz = fxz * 10^Exz
+
+xy_xz = xy - xz
+disp(xy_xz,'xy_xz = ')
\ No newline at end of file diff --git a/243/CH3/EX3.3/3_03.sce b/243/CH3/EX3.3/3_03.sce new file mode 100755 index 000000000..43e1f5712 --- /dev/null +++ b/243/CH3/EX3.3/3_03.sce @@ -0,0 +1,25 @@ +//Example No. 3_03
+//Decimal to Binary
+//Pg No. 47
+clear; close ; clc;
+
+d = 43.375 ;
+//Separating integral part and fractional parts
+dint = floor(d)
+dfrac = d - dint
+
+//Integral Part
+i = 1 ;
+intp = dec2bin(dint)
+
+//Fractional part
+j = 1 ;
+while dfrac ~= 0
+ fracp(j) = floor(dfrac*2)
+ dfrac = dfrac*2 - floor(dfrac*2)
+ j = j+1 ;
+end
+fracp = strcat(string(fracp))
+
+b = strcat([intp,fracp],'.') //combining integral part and fractional part
+disp(b,'Binary equivalent = ')
\ No newline at end of file diff --git a/243/CH3/EX3.4/3_04.sce b/243/CH3/EX3.4/3_04.sce new file mode 100755 index 000000000..4a42f83d3 --- /dev/null +++ b/243/CH3/EX3.4/3_04.sce @@ -0,0 +1,8 @@ +//Example No. 3_04
+//Decimal to Octal
+//Pg No. 48
+clear ; close ; clc ;
+
+d = 163 ;
+oct = dec2oct(d)
+disp(oct,'Octal number = ')
\ No newline at end of file diff --git a/243/CH3/EX3.5/3_05.sce b/243/CH3/EX3.5/3_05.sce new file mode 100755 index 000000000..53d61068c --- /dev/null +++ b/243/CH3/EX3.5/3_05.sce @@ -0,0 +1,33 @@ +//Example No. 3_05
+//Decimal to binary
+//Pg No. 48
+clear ; close ; clc ;
+
+d = 0.65
+j = 1 ;
+
+while d ~= 0
+ fracp(j) = floor(d*2) //integral part of d*2
+ d = d*2 - floor(d*2) //Fractional part of d*2
+ j = j+1 ;
+ decp(j-1) = d
+ p = 1
+
+ for i = 1:j-2
+ if abs(d - decp(i))< 0.001 then //Condition for terminating the recurring binary equivalent by
+ p = 0 //finding out if the new fractional part is equal to any of the previous fractonal parts
+ break
+ end
+ end
+
+ if p == 0 then
+ break
+ end
+
+end
+rec_p = fracp(i+1:j-1) //Recurring part
+
+rec_p = strcat(string(rec_p))
+fracp = strcat(string(fracp))
+
+disp(strcat( [fracp,rec_p] ),'Binary equivalent = ')
diff --git a/243/CH3/EX3.6/3_06.sce b/243/CH3/EX3.6/3_06.sce new file mode 100755 index 000000000..7ed49abcb --- /dev/null +++ b/243/CH3/EX3.6/3_06.sce @@ -0,0 +1,31 @@ +//Example No. 3_06
+//Octal to Hexadecimal
+//Pg No. 49
+clear ; close ; clc ;
+
+oct = '243' ;
+u = str2code(oct)
+n = length(u)
+for i = 1:n
+ b(i) = dec2bin(u(i)) //Converting each digit to binary equivalent
+ if length(b(i)) == 2 then //making the binary equivalents into a groups of triplets
+ b(i) = strcat(['0',b(i)])
+ elseif length(b(i)) == 1
+ b(i) = strcat(['0','0',b(i)])
+ end
+end
+bin = strcat(b) //combining all the triplets
+i = 1 ;
+while length(bin) > 4
+ OtoH = strsplit(bin,length(bin)-4) //splitting the binary equivalent into groups of binary quadruplets
+ bin = OtoH(1)
+ h(i) = OtoH(2)
+ i = i+1
+end
+h(i) = bin ;
+h = h($:-1:1)
+h = bin2dec(h)
+h = dec2hex(h)
+h = strcat(h)
+
+disp(h,'Hexadecimal equivalent of octal number 243 is ')
diff --git a/243/CH3/EX3.7/3_07.sce b/243/CH3/EX3.7/3_07.sce new file mode 100755 index 000000000..cc87c2d80 --- /dev/null +++ b/243/CH3/EX3.7/3_07.sce @@ -0,0 +1,40 @@ +//Example No. 3_07
+//Hexadecimal to Octal
+//Pg No. 49
+clear ; close ; clc ;
+
+h = '39.B8' ;
+h = strsplit(h,'.') //separating integral part and fractional part
+cint = abs(str2code(h(1)))
+cfrac = abs(str2code(h(2)))
+bint = dec2bin(cint)
+bfrac = dec2bin(cfrac)
+bint = strcat(bint)
+bfrac = strcat(bfrac)
+
+//Integral Part
+i = 1 ;
+while length(bint) > 3
+ HtoO = strsplit(bint,length(bint)-3)
+ bint = HtoO(1)
+ oint(i) = HtoO(2)
+ i = i+1 ;
+end
+oint(i) = bint
+oint =oint($:-1:1)
+oint = bin2dec(oint)
+
+//Fraction Part
+i = 1 ;
+while length(bfrac)> 3
+ HtoO = strsplit(bfrac,3)
+ bfrac = HtoO(2)
+ ofrac(i) = HtoO(1)
+ i = i+1
+end
+ofrac(i) = bfrac
+ofrac = bin2dec(ofrac)
+
+//Combining integral part and fraction part
+oct = strcat([strcat(string(oint)),strcat(string(ofrac))],'.')
+disp(oct,'Octal number equivalent of Hexadecimal number 39.B8 is ')
diff --git a/243/CH3/EX3.8/3_08.sce b/243/CH3/EX3.8/3_08.sce new file mode 100755 index 000000000..3bb6c8c42 --- /dev/null +++ b/243/CH3/EX3.8/3_08.sce @@ -0,0 +1,14 @@ +//Example No. 3_08
+//-ve Integer to binary
+//Pg No. 50
+clear ; close ; clc ;
+
+negint = -13
+posbin = dec2bin(abs(negint))
+posbin = strcat(['0',posbin])
+compl_1 = strsubst(posbin,'0','d')
+compl_1 = strsubst(compl_1,'1','0')
+compl_1 = strsubst(compl_1,'d','1')
+compl_2 = dec2bin(bin2dec(compl_1) + 1)
+
+disp(compl_2,'Binary equivalent of -13 is ')
\ No newline at end of file diff --git a/243/CH3/EX3.9/3_09.sce b/243/CH3/EX3.9/3_09.sce new file mode 100755 index 000000000..0e8521997 --- /dev/null +++ b/243/CH3/EX3.9/3_09.sce @@ -0,0 +1,28 @@ +//Example No. 3_09
+//Binary representation
+//Pg No. 51
+clear ;close ;clc ;
+
+n = -32768
+compl_32767 = dec2bin(bitcmp(abs(n)-1,16) + 1)
+disp(compl_32767,'binary equivalent of -32767 is ')
+
+n_1 = -1
+dcomp = bitcmp(1,16)
+compl_1 = dec2bin(dcomp+1)
+disp(compl_1,'binary equivalent of -1 is ')
+compl_32767_code = str2code(compl_32767)
+compl_1_code = str2code(compl_1)
+summ(1) = 1 //since -32768 is a negative number
+c = 0
+for i = 16:-1:2
+ summ(i) = compl_32767_code(i) + compl_1_code(i)+c
+ if summ(i) == 2 then
+ summ(i) = 0
+ c = 1
+ else
+ c = 0
+ end
+end
+binfinal = strcat(string(summ))
+disp(binfinal,'Binary equivalent of -32768 in a 16 bit word is ')
|