blob: 6e5020d7d196a9c9e3abb2dead5504f50e0793c1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
//example 10.13
clc;
clear
//pre=input("Enter the number where the counter is preset");
pre = 1001; // given preset value
q=1;
b=0;
f=0;
a=pre;
while(a>0) //converting to decimal
r=modulo(a,10);
b(1,q)=r;
a=a/10;
a=floor(a);
q=q+1;
end
for m=1:q-1
c=m-1
f = f + b(1,m)*(2^c);
end
disp("The counter will count down to 15 , Then preset back to %d, The resulting state diagram is shown below");
for k=1:3
for i=9:-1:0 // this will print the states
printf('%d ',i);
end;
printf('15 ');
end;
|