Solved

# hexidecimal values

Posted on 2005-04-27
5,864 Views
hi,
how do I know what is the value of &H80000 in C# and how do I know what is the value of 0x890009 in VB, is there any algorithm to find out all that..? how the heck am I gonna know what &H80000 means..? I know MessageBox.Show(&H80000), but that's not what I want! sometimes I have to use this values from Platform SDK and I have no idea how to declare them in VB, can you help me...?

#define DCX_WINDOW           0x00000001L
#define DCX_CACHE            0x00000002L
#define DCX_NORESETATTRS     0x00000004L
#define DCX_CLIPCHILDREN     0x00000008L
#define DCX_CLIPSIBLINGS     0x00000010L
#define DCX_PARENTCLIP       0x00000020L
#define DCX_EXCLUDERGN       0x00000040L
#define DCX_INTERSECTRGN     0x00000080L
#define DCX_EXCLUDEUPDATE    0x00000100L
#define DCX_INTERSECTUPDATE  0x00000200L
#define DCX_LOCKWINDOWUPDATE 0x00000400L
0
Question by:davidlars99

LVL 96

Expert Comment

I am not quite sure what you are asking.

Do you want to convert these define statements to VB?

And, do you want to have cross-platforms function to convert values from VB into C#, and values from C# into VB?

Bob
0

LVL 85

Assisted Solution

This

#define DCX_WINDOW           0x00000001L

would become

Private Const DCX_WINDOW As Integer = &H1

So you change

#define

to

Private Const
' or
Public Const
' or
Const

then the

0x

becomes

&H

and you drop all the leadings zeroes after the "0x" and remove the "L" at the end.
0

LVL 24

Accepted Solution

You can also convert the numbers to decimal numbers if its easier for you to deal with... each position is in base 16, where A=10, B=11, C=12, D=13, E=14, F=15

So.... the "thousands" column is really x16^3, the "hundreds" are x16^2=256 and the tens are x16

so F =15, 1F = 16+15=31, 2F = 32+15 = 47, etc.... A=10, B=11, C=12, D=13, E=14, F=15

Most of the reason that hexadecimal numbers are used while coding is to make the results of the bit-wise AND and OR operators more clear...
0

LVL 9

Expert Comment

Use the convert function to convert hex to decimal, string, whatever.

dim i as integer = Convert.ToInt32(&H2L)
dim s as string = Convert.ToString(&H2L)
0

LVL 13

Author Comment

@ Idle_Mind
> and you drop all the leadings zeroes after the "0x" and remove the "L" at the end.

@  Chaosian
> So.... the "thousands" column is really x16^3, the "hundreds" are x16^2=256 and the tens are x16 so F =15, 1F = 16+15=31, 2F = 32+15 = 47, etc.... A=10, B=11, C=12, D=13, E=14, F=15

so according to this comment, following example should be true right..?

0x00000001=&H1
0x00000040=&H40
0x00000200=&H200
0x0000FFFF=&H15151515  or  &H60
0xFFFF0000=???

I'm still a bit confused...  :o)
0

LVL 96

Assisted Solution

0xFFFF0000=&HFFFF0000
0x0000FFFF =&HFFFF

Bob
0

LVL 24

Expert Comment

0x0000FFFF= &HFFFF or 15x16^3 + 15x16^2 + 15x16^1 + 15x16^0 = 65535 (decimal)
0

LVL 44

Assisted Solution

just to further amplify Chaosian's comments about bit-wise meanings of Hex values:

Hex Value                                         Bits
----------------------------------------------------
0x00000001L                               0000 0000 0000 0000 0000 0000 0000 0001  sets a single bit, at position 0
0x00000002L                               0000 0000 0000 0000 0000 0000 0000 0010
0x00000003L                               0000 0000 0000 0000 0000 0000 0000 0011 sets 2 bits at positions 0 and 1
0x00000004L                               0000 0000 0000 0000 0000 0000 0000 0100
0x00000008L                               0000 0000 0000 0000 0000 0000 0000 1000
0x0000000FL                               0000 0000 0000 0000 0000 0000 0000 1111  sets 4 bits at positions 0, 1, 2 and 3
0x00000010L                               0000 0000 0000 0000 0000 0000 0001 0000
0x00000020L                               0000 0000 0000 0000 0000 0000 0010 0000
0x80000000L                               1000 0000 0000 0000 0000 0000 0000 0000  sets a single bit, at position 31

thus it is not particularly useful to see that value with its DECIMAL represntation.  What is important is which BIT (or bits) are being set, and those are usually set one bit at a time.  Each bit has a specific meaning in the value, as it usually serves to turn on or off a certain feature, or set a certain parameter.

AW

0

LVL 13

Author Comment

what about these values..?

0x1
0x2
0x4
0x8
0x10
0x1F

0xA0000003L
0xC0000004L
#define IO_REPARSE_TAG_SIS                      (0x80000007L)
#define IO_REPARSE_TAG_DFS                      (0x8000000AL)
#define IO_REPARSE_TAG_FILTER_MANAGER           (0x8000000BL)
0

LVL 13

Author Comment

ignore my last post, I didn't see your comments
0

LVL 24

Expert Comment

AW,

Thanks for the help. I have a BEng in hardware engineering, so I often forget they don't teach programmers about bits anymore ;)

To further amplify... the IO_REPARSE_TAG_SIS has the last 3 bits set (0111), IO_REPARSE_TAG_DFS  has 1010, and IO_REPARSE_TAG_FILTER_MANAGER has 1011. The last two are likely performing very similar operations behind the scenes, since these are really composite flags (i.e. more than one bit is turned on by them). Knowing this, you should never see code that sets the flag to IO_REPARSE_TAG_DFS OR IO_REPARSE_TAG_FILTER_MANAGER, since this just sets the flags to the value of IO_REPARSE_TAG_FILTER_MANAGER.
0

LVL 13

Author Comment

I understand everything you explained and thank you all  :) what I don't undestand is how to determine the integer value of these

&H2FF or &HF2FF or &HFFF2F

I tryed similar based on Chaosian's calculation below and haven't been able to do it with number(s) in between letters

> 0x0000FFFF= &HFFFF or 15x16^3 + 15x16^2 + 15x16^1 + 15x16^0 = 65535 (decimal)

or even with 2 or more number like this: &HF234FF
0

LVL 44

Expert Comment

2FF Hex = 2*256 + 15*16 + 15 = 512 + 240 + 25 = 767
2             F           F

F2FF Hex = 15 * 4096 +  2*256 + 15*16 + 15 = 62207
F                 2            F           F

FFF2F Hex = 1048367 Dec = 15 * 65536 + 15* 4096 + 15*256 + 2*16 + 15
F                  F                F            2          F

F234FF Hex = 15873279 = 15 * 1048576 + 2 * 65356 + 3 * 1024 + 4 * 256 + 15*16 + 15
F                    2                 3               4              F           F
16^4 = 1048576
16^3 = 65356
16^2 = 256
16^1 = 16
a6^0 = 1

remember F = 15, so F00000 = 15 * (16^4) + (0*16^3) + (0*16^2) + (0*16^1) + (0 * 16^0)
F                     0                0                0                0

AW
0

LVL 24

Expert Comment

AW is right on... as I stated earlier, A=10, B=11, C=12, D=13, E=14 and F=15...

Think of it this way. Each column is a power of 16, just like the decimal system. In decimal, you have 10^n....10^3 (thousands), 10^2 (hundreds), 10^1 (tens), and 10^0 (ones). In hex, you have 16^n, ... , 16^3, 16^2, 16^1 and 16^0. Hex is really just a convenient system for representing large binary numbers, since each group of four binary digits becomes a single hex character. This is why Arthur Wood groups the binary number into 4-digit groups, above.

So... to translate hex to decimal, you take each hex digit and multiply it's decimal representation (i.e. F=15) by sixteen raised to the appropriate power (remembering the right-most digit is always multiplied be one).

Hope this helps.
0

LVL 13

Author Comment

perfect explanations make perfect sense, only thing that doesn't make sense is a such distinction for VB and Cx hex values, thanks to everybody for helping me... hexes bug me no more  :)
0

LVL 39

Expert Comment

Use calc.exe to easily convert numbers:

- type WIN + R
- type calc
- choose scientific view
- check HEX radio button
- type HEX number (without 0x or H)
- check DEC radio button

Voilà.

Regards, Alex
0

LVL 13

Author Comment

thanks itsmeandnobodyelse, that is cool... I like that quick method!
0

## Write Comment

Please enter a first name

Please enter a last name

We will never share this with anyone.

## Featured Post

XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…

#### 759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

#### Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!