符号幅度,一个补码,两个补码 [英] Sign magnitude, One's complement, Two's Complement

查看:280
本文介绍了符号幅度,一个补码,两个补码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我的教授有一个问题要列出可以用一个,两个补数和符号幅度表示的所有正数和负数:

So my professor has a question to make a list of all positive and negative numbers that can be represented in One's, two's complements, and sign magnitude:

使用4位数字,例如(5)10 =(0101)2 写下所有可以用符号位的四个位,一个补码和两个补码表示的所有正数和所有负数.

Using 4 bit numbers, for example (5)10 = ( 0101)2 Write all positive numbers and all negative numbers that can be represented with four bits in sign-magnitude, one’s complement, and two’s complement.

现在,我不是在寻找答案,只是为了澄清.

Now, I am not looking for the answer just clarification.

    对于符号幅度,第一位代表数字的符号. 因此,在所提供的示例中,负5是-5 =(1101), 补码=(0101)二进制补码(1010)
  • 符号幅度仅允许三位显示数字,一位用于显示 符号(从右到左的前导位).这意味着 我们只有8种组合.所以是0-7和-0-之间的数字 (-6)一人一二,我们有16个?所以0-15和-0-(-15)
  • for sign magnitude, the first bit represents the sign of the number. so in the example provided, negative five is -5= (1101), The ones complement = (0101) the twos complement (1010)
  • Sign magnitude only allows for three bits to show number and one for the sign (the leading bit from right to left.) This would mean that we only have 8 combinations. so that is numbers from 0-7 and -0- (-6) Ones and twos we have 16? so 0-15 and -0-(-15)

有人可以更好地解释这个问题吗?

can someone explain this question better?

推荐答案

下面简要介绍了您提到的所有三种表示技术.

Here's a brief description about all the three representation techniques you've mentioned.

在此表示中,我们可以表示任意位数(2的幂)的数字.表示中有两个部分.顾名思义,符号和幅度.

In this representation, we can represent numbers in any number of bits (powers of 2). There are two parts in the representation. Sign and Magnitude, as the name implies.

如果我们想用n个位数表示一个数字,

If we want to represent a number in n number of bits,

  • 第一位始终代表数字的符号.即0代表正数,1代表负数.
  • 其余的位(n-1)代表二进制数的大小.

例如如果要使用8位表示+25和-25: (+25)10 = 0011001和(-25)10 = 10011001

e.g. If you want to represent +25 and -25 using 8 bits: (+25)10 = 0011001 and (-25)10 = 10011001

由于二进制数制只有2位数字(0和1),所以一位的补码是另一位.即0的补码为1,反之亦然.

Since Binary number system has only 2 digits (0 and 1), the complement of one digit is the other. i.e. the complement of 0 is 1 and vice versa.

在此表示中,没有特定的位来表示该符号,但是可以使用MSB(最高有效位)来确定该数字的符号.即,如果数字为正,则MSB为0;如果数字为负,则MSB为1.使用二进制数,并且还使用特定的位大小. (例如8、16、32等位).

In this representation, there is no specific bit to represent the sign, but the MSB (Most Significant Bit) can be used to determine the sign of the number. i.e. MSB is 0 if the number is positive and 1 if the number is negative. Binary numbers are used and also a specific bit size is used. (e.g. 8, 16, 32, etc. bits).

  1. 如果数字为正数

  1. If the number is positive

  • 将数字转换为二进制
  • 将数字设置为特定的位大小

如果数字为负

  • 将数字转换为二进制
  • 将数字设置为特定的位大小
  • 获取该值的补语

例如再次以前面的例子为例

e.g. Take the previous example again

  • (+ 25)10
    • 将数字转换为二进制->(11001)2
    • 将数字设置为特定的位大小->(0001 1001)
    • (+25)10
      • Convert the number to binary -> (11001)2
      • Set the number to specific bit size -> (0001 1001)
      • 将数字转换为二进制->(11001)2
      • 将数字设置为特定的位大小->(0001 1001)
      • 获取该值的补数->(1110 0110)

      这种表示技术与一个人的补码表示非常相似.主要区别在于,当数字为负数时,获得补数后,LSB(最低有效位)将加1.

      This representation technique is very much similar to One's Complement Representation. The main difference is that when the number is negative, 1 is added to the LSB (Least Significant Bit) after getting the complement.

      例如让我们以同样的例子

      e.g. Let us take the same example

      • (+ 25)10
        • 将数字转换为二进制->(11001)2
        • 将数字设置为特定的位大小->(0001 1001)
        • (+25)10
          • Convert the number to binary -> (11001)2
          • Set the number to specific bit size -> (0001 1001)
          • 将数字转换为二进制->(11001)2
          • 将数字设置为特定的位大小->(0001 1001)
          • 获取该值的补数->(1110 0110)
          • 将1添加到LSB->(1110 0110)+1 =(1110 0111)

          这篇关于符号幅度,一个补码,两个补码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆