blob: 787eb006c4305768707e86d1dc37d5403a95c4bc (
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
//Chapter 04:Number Theory and Cryptography
clc;
clear all;
dec=[]
d=0
i=1
disp('Please enter input in inverted commas')
hex=input("Enter the hexadecimal number:")
l=length(hex)
hex=strsplit(hex)
cn=0
for i=l:-1:1
select hex(i)
case 'A' then
d=10
case 'B' then
d=11
case 'C' then
d=12
case 'D' then
d=13
case 'E' then
d=14
case 'F' then
d=15
case 'a' then
d=10
case 'b' then
d=11
case 'c' then
d=12
case 'd' then
d=13
case 'e' then
d=14
case 'f' then
d=15
else
d=eval(hex(i))
end
dec=dec+ (d) *(16**cn)
cn=cn+1
end
disp(dec)
|