十六进制值如何按位操作? [英] How is a Hex Value manipulated bitwise?

查看:612
本文介绍了十六进制值如何按位操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对按位运算符有一个非常基本的了解.但是我不知该如何分配值.如果有人能指出正确的方向,我将不胜感激.

I have a very basic understanding of bitwise operators. I am at a loss to understand how the value is assigned however. If someone can point me in the right direction I would be very grateful.

我的十六进制地址:0xE0074000

My Hex Address: 0xE0074000

十进制值:3758571520

The Decimal value: 3758571520

二进制值:11100000000001110100000000000000

The Binary Value: 11100000000001110100000000000000

我正在尝试编写一个简单的微控制器,并使用Microsoft .Net Micro Framework中的Register访问类使该控制器执行我想做的事情.

I am trying to program a simple Micro Controller and use the Register access Class in the Microsoft .Net Micro Framework to make the Controller do what I want it to do.

Register T2IR = new Register(0xE0074000);
T2IR.Write(1 << 22);

在上面的示例中,二进制表示中的位如何移动?我不明白如何将位管理以二进制形式分配给该地址.

In my above example, how are the bits in the Binary representation moved? I don’t understand how the management of bits is assigned to the address in Binary form.

如果有人可以将我指向正确的方向,我会感到非常满足.

If someone can point me in the right direction I would be very greatfull.

推荐答案

忘记开始的小数位.您稍后再讲.

Forget about decimals for a start. You'll get back to that later.

首先,您需要了解HEX和BINARY之间的逻辑.

First you need to see the logic between HEX and BINARY.

好的,对于一个字节,您有8位(#7-0)

Okay, for a byte you have 8 bits (#7-0)

#7 = 0x80 = %1000 0000
#6 = 0x40 = %0100 0000
#5 = 0x20 = %0010 0000
#4 = 0x10 = %0001 0000

#3 = 0x08 = %0000 1000
#2 = 0x04 = %0000 0100
#1 = 0x02 = %0000 0010
#0 = 0x01 = %0000 0001

以二进制形式读取时,以字节为单位,例如%00001000

When you read that in binary, in a byte, like this one %00001000

然后将位设置为第3位(即第3位)的第4位,其值为08十六进制(实际上也是十进制,但在找出十六进制/二进制值时仍会忘记十进制)

Then the bit set, is the 4th from right aka bit #3 which has a value of 08 hex (in fact also decimal, but still forget about decimal while you figure out hex/binary)

现在,如果我们拥有二进制数%10000000 这是打开的#7位.十六进制值为0x80

Now if we have the binary number %10000000 This is the #7 bit which is on. That has a hex value of 0x80

因此,您要做的就是将它们汇总为半字节"(十六进制字节的每个部分都被一些极客称为半字节)

So all you have to do is to sum them up in "nibbles" (each part of the hex byte is called a nibble by some geeks)

您可以通过半字节获得的最大值是(十进制)15或F,分别为0x10 + 0x20 + 0x40 + 0x80 = 0xF0 =二进制%11110000

the maximum you can get in a nibble is (decimal) 15 or F as 0x10 + 0x20 + 0x40 + 0x80 = 0xF0 = binary %11110000

所以所有的光(四位)都以四位亮起= F(十六进制)(十进制15)

so all lights on (4 bits) in a nibble = F in hex (15 decimal)

下半位相同.

您看到图案了吗?

这篇关于十六进制值如何按位操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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