473,394 Members | 1,746 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Hex() in C#

ano
Hi,

Does C# have an equivalent function of Hex() -> "Returns a string
representing the hexadecimal value of an integer" in VB?

thanks,
Jun 27 '06 #1
8 3948
Does .ToString("X2") do what you need?

Marc
Jun 27 '06 #2
ano
Thanks Marc, how about "VarPtr()"?
I have created this function. Is it work as VarPtr() in VB?

private static int VarPtr(object o)
{
System.Runtime.InteropServices.GCHandle GC;
GC = System.Runtime.InteropServices.GCHandle.Alloc(o,
System.Runtime.InteropServices.GCHandleType.Pinned );

int ret = GC.AddrOfPinnedObject().ToInt32();

GC.Free();
return ret;
}
"Marc Gravell" wrote:
Does .ToString("X2") do what you need?

Marc

Jun 27 '06 #3
Damned if I know... looks like some code I found on google, but my gut tells
me that it might not work as expected after you have Free()'d the handle...
this may unpin the object rendering the address useless? I'm talking
gut-feel here - this isn't something I've ever done...

If this method is provided by the VB.Net migration dlls, you might want to
reference these dlls (from C# - not a problem) to use them directly? Else
load in reflector and see what they do...

Marc

Jun 27 '06 #4
ano
Thanks, I think this way looks easier : )

"Marc Gravell" wrote:
Damned if I know... looks like some code I found on google, but my gut tells
me that it might not work as expected after you have Free()'d the handle...
this may unpin the object rendering the address useless? I'm talking
gut-feel here - this isn't something I've ever done...

If this method is provided by the VB.Net migration dlls, you might want to
reference these dlls (from C# - not a problem) to use them directly? Else
load in reflector and see what they do...

Marc

Jun 27 '06 #5
Hi,

Why you convert it to int32 ?

IMO you should keep it as IntPtr, it's more descriptive and less error
prone.

I feel the same regarding the Free call, you are releasing it so maybe you
lost the referenced memory.

--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"ano" <an*@discussions.microsoft.com> wrote in message
news:9B**********************************@microsof t.com...
Thanks Marc, how about "VarPtr()"?
I have created this function. Is it work as VarPtr() in VB?

private static int VarPtr(object o)
{
System.Runtime.InteropServices.GCHandle GC;
GC = System.Runtime.InteropServices.GCHandle.Alloc(o,
System.Runtime.InteropServices.GCHandleType.Pinned );

int ret = GC.AddrOfPinnedObject().ToInt32();

GC.Free();
return ret;
}
"Marc Gravell" wrote:
Does .ToString("X2") do what you need?

Marc

Jun 27 '06 #6
ano
Hi Ignacio Machin ,

I'm not sure about this function because I found it in Google.
I tried to add the reference to Microsoft.VisualBasic but I didn't see
VarPtr() function.

Could you explain more about how to use IntPtr?

thanks,
ano
"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,

Why you convert it to int32 ?

IMO you should keep it as IntPtr, it's more descriptive and less error
prone.

I feel the same regarding the Free call, you are releasing it so maybe you
lost the referenced memory.

--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"ano" <an*@discussions.microsoft.com> wrote in message
news:9B**********************************@microsof t.com...
Thanks Marc, how about "VarPtr()"?
I have created this function. Is it work as VarPtr() in VB?

private static int VarPtr(object o)
{
System.Runtime.InteropServices.GCHandle GC;
GC = System.Runtime.InteropServices.GCHandle.Alloc(o,
System.Runtime.InteropServices.GCHandleType.Pinned );

int ret = GC.AddrOfPinnedObject().ToInt32();

GC.Free();
return ret;
}
"Marc Gravell" wrote:
Does .ToString("X2") do what you need?

Marc


Jun 27 '06 #7
ano wrote:
I'm not sure about this function because I found it in Google.
I tried to add the reference to Microsoft.VisualBasic but I didn't see
VarPtr() function.


What are you doing that requires VarPtr? Perhaps there is another way
to accomplish what you want.

Jun 27 '06 #8
Damned if I know... looks like some code I found on google, but my gut tells
me that it might not work as expected after you have Free()'d the handle...
this may unpin the object rendering the address useless? I'm talking
gut-feel here - this isn't something I've ever done...


You're right, the code is definitely broken and the "pointer" it
returns is useless.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jun 27 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: DvGrimm | last post by:
Any help would be very, very much appreciated... I've been searching the net (google) for 4 days now trying to find a php function to convert hex to floating point. I'm converting old...
6
by: Bengt Richter | last post by:
>>> hex(-5) __main__:1: FutureWarning: hex()/oct() of negative int will return a signed string in Python 2.4 and up '0xfffffffb' >>> hex(-5) '0xfffffffb' >>> hex(-5L) '-0x5L' That is sooo...
16
by: Delali Dzirasa | last post by:
I would have a number packed with its hex representation of the integer below is some sample code of what is being done. int value = 20; //in hex it is 0x14 AddData (value); .. .. ..
9
by: Niels Jensen | last post by:
Hi All, I'm desperately looking for help regarding the following: I need to make a hexmap in it's own scrollable window on a form, when I say hex map I mean a graphical hexagon surrounded by...
5
by: kuukelekuu | last post by:
I need to convert ascii chars to hex chars. I searched the internet, found hex to ascii, but nowhere is there a ascii to hex method created by anyone. Can anyone help me with that? Chears
28
by: James Brown | last post by:
All, I have a series of characters which I need to convert to integer values. Each character is read in turn from a function 'nextch', and hex-digits are identified by the isxdigit function - so...
1
by: Stephen Cattaneo | last post by:
Hi all, I am relatively new to socket programming. I am attempting to use raw sockets to spoof my IP address. From what I can tell I will have to build from the Ethernet layer on up. This is...
5
by: Filipe Teixeira | last post by:
Hi. I have to open a binary file from an old computer and recover the information stored (or at least try to). I use: f=open('file.bin','rb') a=f.read() f.close() a in now a string full...
0
Frinavale
by: Frinavale | last post by:
Convert a Hex number into a decimal number and a decimal number to Hex number This is a very simple script that converts decimal numbers into hex values and hex values into decimal numbers. The...
1
by: Hugo Andrade | last post by:
I want to extract the jpg image from an Hex file. The hex file comes from a serial camera that outputs a hex stream in the serial port. I need to reconstruct the image. The output of the camera is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.