전자/마이크로프로세서

마이크로 프로세서 강의정리1-2 ( number system, 이진수 8,16진수 변환, 보수 계산 )

런앤두 2021. 3. 5. 17:08

#Number system (시험에 가끔 등장하는 파트)

 

-conventional number system

1. non- redundant

2. weighted   10진수 -> 91 9*10(십) 9*1(단), 2진수 ->64 + 16 + 8 + 2 + 1 = 1011011(2)

3. postional -> radix system

 

-decimal number system

r=10

s={0,~9}  

ex) 2*10^2+7*10^1+3*10^0 = 273

 

-binary number system

r=2

s={0,1}

ex) 1*2^2+0*2^1+1*2^0 =101(2)

 

-hexadecimal number system

r=16

s={0,~9,A,B,~F}

ex) 10*16^1+7*16^0=167

 

binary number system 수식을 시그마 수식으로 표현한경우

 

101(2) = 1*2^2+0*2^1+1 = 5(10) ->인티져 부분

11.01(2) = 1*2^1+1+0*2^-1+1*2^-2 = 3 + 1/2^2 = 3.25(10)

 

32bit / 1010 1011 ..........1011(32 자리 사용),  FFFFFFFF(16진수의 경우 8자리만 사용)

 

2^0 = 1, 2^8 = 256, 2^10 = 1024  ≈ 10^3 1K, 2^32 = 4*2^30 = 4G

 

<number base conversion>

- Decimal to Binary

1. integer part -> keep dividing by 2

2. fraction part -> keep multiplying by 2

 

27.325(10) = 27 + 0.375

역순으로 계산 하는 이유?

27=2*(2*(2*(2*(2*0+1)+1)+0)+1)+1) -->맨 안쪽1의 경우 2가 4번 곱해져야함 즉 2^4의 값이 되는 것

=1*2^4+1*2^3+0*2^2+1*2^1+1*2^0

=11011(2)

 

이러한 방식을 사용해도 되지만 정통은 아니다.

 

0.375*2=0.75

0.75*2=1.5

0.5*2=1

1.375=1/2*(0+1/2*(1+1/2*(1+0))) --> 1/2와 0.75가 곱해짐

=0*1/2+1*1/2^2+1*1/2^3

=0.011(2)

 

27.375(10) = 27(10) + 0.375(10) = 11011(2) + 0.011(2) = 11011.011(2)

 

모든 변환은 바이너리를 거치는 것이 편안하다.

 

binary <-> octal / 101/110/101(2) = 565(2)

binart <-> hexadecimal 1110/1010(2) = EA(16)

octal <-> hexadecimal -> use binary!!

 

complement of numbers

-complement 

A + B =C => A is the C's complement of B

 

ex) 2+8=10 2는 8의 10의 보수이다. / 4+7=11 7은 4의 11의 보수이다.

 

왜 보수인가? 덧셈기로 뺄셈이가능 뺄셈이 가능하면 곱셈 나눗셈이가능하고 더 나아가 series function 까지 사용이 가능

 

Complement for subtration

 

X-Y = { X - Y if X >= Y

        { -(Y-X) if X<Y

 

what operation do we need?

1. comparasion

2. X-Y for X>=Y + negative number

 

-complement  Y-(R-Y) = R   R-Y는 Y의 R의 보수

-y => R-Y, when R is a constant -(-Y) = R - (R-Y) = Y

 

X-Y = X+(-Y) = X+R-Y = R + (X-Y) = R-(Y-X)

 

if x>=y, then get rid of R

if x<y, then R-(Y-X) is the answer

-(Y-X) => R - (Y-X) 보수화

 

R=1000

Ex1)362 - 257 

-257 = 1000-257 = 743

362-257 = 362 + (-257) = 362 + 743  = 1105 = 1000 + 105

 

362 > 257 R을 제거 => 105

 

Ex2)349 - 429

-429 = 1000 - 429 

- 429 = 1000 - 429 = 571

349 - 429 = 349 + (-429)

= 329 + 571

= 920

= 1000 - 80 => -80