Solved

# hexidecimal values

Posted on 2005-04-27
Medium Priority
5,931 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
• 6
• 4
• 2
• +4

LVL 96

Expert Comment

ID: 13876491
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 86

Assisted Solution

Mike Tomlinson earned 400 total points
ID: 13876558
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

Jeff Certain earned 800 total points
ID: 13878205
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

ID: 13878902
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

ID: 13879240

@ 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

Bob Learned earned 400 total points
ID: 13879252
0xFFFF0000=&HFFFF0000
0x0000FFFF =&HFFFF

Bob
0

LVL 24

Expert Comment

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

LVL 44

Assisted Solution

Arthur_Wood earned 400 total points
ID: 13879273
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

ID: 13879304

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

ID: 13879323
0

LVL 24

Expert Comment

ID: 13879509
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

ID: 13880237
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

ID: 13880413
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

ID: 13880515
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

ID: 13882173
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

ID: 13886259
Use calc.exe to easily convert numbers:

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

VoilÃ .

Regards, Alex
0

LVL 13

Author Comment

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

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and lâ€¦
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's aâ€¦
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased riskâ€¦
###### Suggested Courses
Course of the Month16 days, 23 hours left to enroll