|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
64 HI/LO DWORD extraction vb.netIm trying to create 64 bit integer structure in vb.net that i can extract the HI/LO parts from like you would in c++ using bit masking etc. I would have liked to beable to use an unsigned 64 bit int but it seems vb.net doesn't like me and spits out all kind of errors when i try to do bitwise operations on unsigned values. Im quite new to vb.net so dont bash me if there is an easier way to achieve this but here goes, this is what i have done so far:- private structure _LARGE_INTEGER ' 64 bit integer dim QuadPart as System.Int64 function GetLowPart() as System.Int32 return (me.QuadPart and &HFFFFFFFF) end function function GetHighPart() as System.Int32 return (me.QuadPart >> &H20) end function end structure Now the HI part extraction works fine simply by shifting to the right ( i love the new vb operators :) ) by 32 bits. The problem occurs when i attempt to extract the LO part by masking off the lower 32 bits, this returns an overflow! Now i have tried messing around with conversions and what not to ensure the type is interpreted correctly but i keep getting this overflow and it's driving me nuts anyone had this problem?? A further note if i mask off 0xfffffff ( 28 bytes ) it works fine. Thanks in advance. -------------------------------- From: ben ----------------------- Posted by a user from .NET 247 (http://www.dotnet247.com/) <Id>uQ8dmyX4vEGNb64Hx/A88Q==</Id> >Im quite new to vb.net so dont bash me if there is an easier way to achieve this but here goes, this is what i have done so far:- I don't see why you need the structure, when you could do this inlinewith the bitwise operators. Show quoteHide quote > First I recommend you turn on Option Strict so that it actually gives> private structure _LARGE_INTEGER > > ' 64 bit integer > dim QuadPart as System.Int64 > > function GetLowPart() as System.Int32 > return (me.QuadPart and &HFFFFFFFF) > end function > > function GetHighPart() as System.Int32 > return (me.QuadPart >> &H20) > end function > > end structure > >Now the HI part extraction works fine simply by shifting to the right ( i love the new vb operators :) ) by 32 bits. The problem occurs when i attempt to extract the LO part by masking off the lower 32 bits, this returns an overflow! a compiler error. The solution would be something like this function GetLowPart() as System.Int32 return CInt(me.QuadPart and &HFFFFFFFFL) end function function GetHighPart() as System.Int32 return CInt(me.QuadPart >> &H20) end function Mattias -- Mattias Sjögren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup. One final detail, I think the code you have will still fail if bit nr 32 is 1 - it will translate into a number too large to fit on a signed integer - you'll have to pad the
resulting long with 1's if that bit is one before converting to an integer. The easiest way I know to do that is to left shift by 32 and then right shift again by 32. Hope that helps, Alex, MS VB QA -------------------- Show quoteHide quote >From: Mattias Sjögren <mattias.dont.want.spam@mvps.org> the LO part by masking off the lower 32 bits, this returns an overflow!>Subject: Re: 64 HI/LO DWORD extraction vb.net >Date: Mon, 07 Mar 2005 22:17:38 +0100 >References: <#qgv1u0IFHA.1***@TK2MSFTNGP10.phx.gbl> >X-Newsreader: Forte Agent 1.8/32.548 >MIME-Version: 1.0 >Content-Type: text/plain; charset=ISO-8859-1 >Content-Transfer-Encoding: 8bit >Message-ID: <OzSLVt1IFHA.2***@TK2MSFTNGP10.phx.gbl> >Newsgroups: microsoft.public.dotnet.languages.vb >NNTP-Posting-Host: g150.ryd.student.liu.se 130.236.238.150 >Lines: 1 >Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl >Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.languages.vb:263846 >X-Tomcat-NG: microsoft.public.dotnet.languages.vb > >>Im quite new to vb.net so dont bash me if there is an easier way to achieve this but here goes, this is what i have done so far:- > >I don't see why you need the structure, when you could do this inline >with the bitwise operators. > > >> >> private structure _LARGE_INTEGER >> >> ' 64 bit integer >> dim QuadPart as System.Int64 >> >> function GetLowPart() as System.Int32 >> return (me.QuadPart and &HFFFFFFFF) >> end function >> >> function GetHighPart() as System.Int32 >> return (me.QuadPart >> &H20) >> end function >> >> end structure >> >>Now the HI part extraction works fine simply by shifting to the right ( i love the new vb operators :) ) by 32 bits. The problem occurs when i attempt to extract Show quoteHide quote > >First I recommend you turn on Option Strict so that it actually gives >a compiler error. The solution would be something like this > > function GetLowPart() as System.Int32 > return CInt(me.QuadPart and &HFFFFFFFFL) > end function > > function GetHighPart() as System.Int32 > return CInt(me.QuadPart >> &H20) > end function > > > > >Mattias > >-- >Mattias Sjögren [MVP] mattias @ mvps.org >http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com >Please reply only to the newsgroup. > >One final detail, I think the code you have will still fail if bit nr 32 is 1 Did you actually try it? It's working fine here.Mattias -- Mattias Sjögren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup. Maybe I'm making some mistake, but here you go:
Module Module1 Sub Main() quadpart = &HFFFFFFFFFL Dim i As Integer = GetLowPart() Console.WriteLine(i) End Sub Dim quadpart As Long Function GetLowPart() As System.Int32 Return (quadpart And &HFFFFFFFF) End Function End Module If I'm correct, this is actually wrong :) - the problem with the and line, is that the integer literal will be converted to long - and since for -1I -> -1L which is basically all bits set, the and won't actually make a difference - so if the long is within the integer range, this will work - however, for a positive value over the integer's range, as in the code above, this will throw an exception. Let me know if I made a mistake - it's been a while since I delved in this particular forest :) Alex, MS VB QA -------------------- >From: Mattias Sjögren <mattias.dont.want.spam@mvps.org> @TK2MSFTNGXA02.phx.gbl>>Subject: Re: 64 HI/LO DWORD extraction vb.net >Date: Fri, 11 Mar 2005 23:57:57 +0100 >References: <#qgv1u0IFHA.1***@TK2MSFTNGP10.phx.gbl> <OzSLVt1IFHA.2***@TK2MSFTNGP10.phx.gbl> <vMwMrqoJFHA.2856 Show quoteHide quote >X-Newsreader: Forte Agent 1.8/32.548 >MIME-Version: 1.0 >Content-Type: text/plain; charset=ISO-8859-1 >Content-Transfer-Encoding: 8bit >Message-ID: <#KvFP2oJFHA.***@TK2MSFTNGP12.phx.gbl> >Newsgroups: microsoft.public.dotnet.languages.vb >NNTP-Posting-Host: g150.ryd.student.liu.se 130.236.238.150 >Lines: 1 >Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl >Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.languages.vb:264698 >X-Tomcat-NG: microsoft.public.dotnet.languages.vb > >>One final detail, I think the code you have will still fail if bit nr 32 is 1 > >Did you actually try it? It's working fine here. > > > >Mattias > >-- >Mattias Sjögren [MVP] mattias @ mvps.org >http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com >Please reply only to the newsgroup. > >Maybe I'm making some mistake, but here you go: Well you're using ben's, the original poster's code. My suggestion was[...] > Function GetLowPart() As System.Int32 > Return (quadpart And &HFFFFFFFF) > End Function Return CInt(QuadPart and &HFFFFFFFFL) Mattias -- Mattias Sjögren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup. Sorry my bad - I mixed up postings.
Alex -------------------- >From: Mattias Sjögren <mattias.dont.want.spam@mvps.org> @TK2MSFTNGXA02.phx.gbl> <#KvFP2oJFHA.***@TK2MSFTNGP12.phx.gbl> <eRYazDALFHA.3***@TK2MSFTNGXA02.phx.gbl>>Subject: Re: 64 HI/LO DWORD extraction vb.net >Date: Tue, 29 Mar 2005 12:29:08 +0200 >References: <#qgv1u0IFHA.1***@TK2MSFTNGP10.phx.gbl> <OzSLVt1IFHA.2***@TK2MSFTNGP10.phx.gbl> <vMwMrqoJFHA.2856 Show quoteHide quote >X-Newsreader: Forte Agent 1.8/32.548 >MIME-Version: 1.0 >Content-Type: text/plain; charset=ISO-8859-1 >Content-Transfer-Encoding: 8bit >Message-ID: <O6F5LoENFHA.3***@TK2MSFTNGP14.phx.gbl> >Newsgroups: microsoft.public.dotnet.languages.vb >NNTP-Posting-Host: g150.ryd.student.liu.se 130.236.238.150 >Lines: 1 >Path: TK2MSFTNGXA03.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP14.phx.gbl >Xref: TK2MSFTNGXA03.phx.gbl microsoft.public.dotnet.languages.vb:268163 >X-Tomcat-NG: microsoft.public.dotnet.languages.vb > > >>Maybe I'm making some mistake, but here you go: >[...] >> Function GetLowPart() As System.Int32 >> Return (quadpart And &HFFFFFFFF) >> End Function > >Well you're using ben's, the original poster's code. My suggestion was > >Return CInt(QuadPart and &HFFFFFFFFL) > > > >Mattias > >-- >Mattias Sjögren [MVP] mattias @ mvps.org >http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com >Please reply only to the newsgroup. >
Excel ADO question
Using a variable to specify the name of a control Datalist/datatable sorting Cannot Get MenuItem's name[Notsolved] Formatting timespan objects how to use CurrentRowIndex for datagrid control ? memory stream XML and unicode problem Writing E-Mail Notfications VB.NET with ADO.NET compilation error. How do I run one project? |
|||||||||||||||||||||||