twos complement

2006-11-03 1:46 am
1. 將以下 2的補數 (twos complement) 轉換成 10 進制
10010101 + 00111111
答案 : - 44

2.fixed point notatoin 題
求 11.10111 的 10進制
答案 : 7.4375

3. 將 twos complement 轉為 ones complement
01111111
答案 : 01111111

求以上3題的step

假若是由 10進制轉成 ones complement 或 twos complement我也沒有問題,
但是反過來, 由twos complement 轉 ones complement 或 10進制便會出錯
另想問到底twos complement 轉 ones complement 或 10進制的方法

回答 (1)

2006-11-03 2:33 am
✔ 最佳答案
In fact, if you know the way change a positive base-2 number to base-10, then you can convert any number in base-2 to base-10 as follows:

For 1-complement, if the number is positive, done.
Else, invert all bits

Reason:
in 1-complement, the +ve and -ve is 1-to-1 correspondent:
e.g. for 5 and -5, 5 = 0101, -5 = 1010
invert all bits in 5, i.e. 0101 => 1010, you get -5
invert all bits in -5, i.e. 1010 => 0101, you get 5

For 2-complement, if the number is positive, done.
Else, substract 1 and invert bit

Reason:
Remember that for -ve number:
1-complement + 1 = 2-complement
=> 1-complement = 2-complement - 1
if you substract 1, you get the 1-complement form


收錄日期: 2021-04-23 15:46:21
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20061102000051KK02631

檢視 Wayback Machine 備份