blob: 47083d0aef7d432682a19b8eeaa89739e60d9018 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
//Example 2-43//
//add -3 to -2 in one's complement using 4 bits//
clc
//clears the window//
clear
//clears all the existing variables//
x=bitcmp(3,4)
y=bitcmp(2,4)
//complement of the decimal number 2//
z=x+y+1
//carry is added//
a=dec2bin(z)
//binary conversion//
disp('binary form of the number obtained by adding -3 to -2')
disp(a)
//result is displayed//
disp('msb is discarded,4 bit representation is the answer in binary form')
a=dec2bin(z-(2^4))
disp(a)
//Final result is displayed//
|