简体   繁体   English

将十六进制转换为二进制补码8位二进制

[英]Converting hex into two's complement 8 bit binary

I am in a CSCI class and we are just learning about program execution. 我在CSCI课堂上,我们只是在学习程序执行。 I am running a program called "Brookshear machine simulator" which was written by the author of the class text book ( Computer Science 11th edition by J. Glenn Brookshear). 我正在运行一个名为“ Brookshear机器模拟器”的程序,该程序由课程课本的作者(J. Glenn Brookshear的《计算机科学》第11版)编写。 The program is intended to add the contents of 11 and 0F, storing the result into F1. 该程序旨在将11和0F的内容相加,并将结果存储到F1中。 I have done everything necessary and produced the hex value in 11 which is 09. I am then asked to convert this into two's complement 8-bit binary, which is where I am having a problem. 我已经做了所有必要的工作,并在11中生成了十六进制值09,然后将其转换为二进制的补码8位二进制数,这是我遇到的问题。 I will be needing to convert some hex values into two's compl 8-bit binary in the future for this lab but I cant figure out how to do it. 将来,在此实验室中,我将需要将一些十六进制值转换为二进制的compl 8位二进制文​​件,但我不知道该怎么做。 Can someone please help me understand what twos comp is and how is it related or the same as 8-bit binary , so I can convert this to two's complement 8-bit binary? 有人可以帮我理解二进制补偿是什么,它与8位二进制有什么关系或相同,所以我可以将其转换为二进制的8位二进制补码? 这是机器模拟器的图片,其中的输入受实验室说明的指导。我的任务是在11(09)中找到十六进制值,然后将其转换为二进制补码8位二进制数。

Here is a picture of the machine simulator with the inputs as directed by the lab instructions. 这是机器模拟器的图片,其中的输入受实验室说明的指导。 My task is to find the hex value in 11 (09) then convert it to twos complement 8-bit binary. 我的任务是在11(09)中找到十六进制值,然后将其转换为二进制补码8位二进制数。

Each hexadecimal digit has a 4 bit binary equivalent: 每个十六进制数字都有一个4位二进制等效项:

0  0000
1  0001
2  0010
3  0011
4  0100
5  0101
6  0110
7  0111
8  1000
9  1001
A  1010
B  1011
C  1100
D  1101
E  1110
F  1111

So if you have a two character hex value, like 09 then you can see that 0 = 0000 and 9 = 1001 , so that would be: 因此,如果您有两个字符的十六进制值(例如09那么您会看到0 = 00009 = 1001 ,那么将是:

00001001

which is an 8 bit value. 这是一个8位的值

This works for any length of hex number of course, so for example 37FF in hex would be 0011011111111111 in binary. 本工程为当然的十六进制数任意长度,因此,例如37FF十六进制将是0011011111111111二进制。

Note that two's complement is irrelevant for your example as the number is positive. 请注意,对于您的示例,二进制补码无关紧要,因为数字为正。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM