How is a Hex Value manipulated bitwise?

bitwise-operators, c#, hex

Solution

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

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

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

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

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)

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)

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

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

same goes for the lower nibble.

Do you see the pattern?

Problem

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. My Hex Address: 0xE0074000 The Decimal value: 3758571520 The Binary Value: 11100000000001110100000000000000 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.

Original source