blob: c961b295cf353fa07e1842fd76498c86097e6a9c (
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
|
//Chapter 04:Number Theory and Cryptography
clc;
clear all;
bin_a=[]
i=1
rem=0
n1=input("Enter 1st binary number:")
n2=input("Enter 2nd binary number:")
t1=n1
t2=n2
while (n1~=0 | n2~=0)
bin_a($+i)=modulo((modulo(n1,10)+modulo(n2,10)+rem),2)
rem=(modulo(n1,10)+modulo(n2,10)+rem)/2
n1=int(n1/10)
n2=int(n2/10)
end
if rem ~=0 then
bin_a($+i)=rem
end
bin_a=int(bin_a)
bin_a=flipdim(bin_a,1)
mprintf("The sum of binary numbers %d and %d is",t1,t2)
disp(bin_a)
|