Re: RtlMoveMemory to read an integer from a file

From: Dmitriy Lapshin [C# / .NET MVP] (x-code_at_no-spam-please.hotpop.com)
Date: 03/10/04


Date: Wed, 10 Mar 2004 12:14:29 +0200

You can also use a BinaryReader's ReadInt32 or ReadInt16 method if you need
to read an int. There are also ReadDouble and ReadDecimal methods.

-- 
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE
"Bill Mittenzwey gateway edi.com>" <bmittenzwey<ATremove space> wrote in
message news:OjdbWdiBEHA.3360@TK2MSFTNGP11.phx.gbl...
> I am trying to read a string of bytes out of a file and convert them into
an
> int. I can make it work in Visual Fox (see below), but I can't seem to get
> the same code to work in c# (see below the fox sample).
>
> Does anyone recognize this or can anyone let me know what I am doing
wrong?
> Is there a better way than the WinAPI?
>
> in fox I can do this:
>
> declare VOID RtlMoveMemory in win32api Double @Dest, Char @Src, Size_T
> BytesToCopy
>
> c = CHR(0) + CHR(0) + CHR(0) + CHR(0) + CHR(0) + CHR(0x80) + CHR(0x50)+
> CHR(0x40)
>
> VariableDecimals= 0
> *This will round to 0 decimals.
> set decimals to (VariableDecimals)
> VariableValue  = 10^(-VariableDecimals)
> VariableLength = 8
> =RtlMoveMemory(@VariableValue, @c,  VariableLength  )
>
> The value of VariableValue will be 66
>
>
> In c#:
> At the top of the class:
> [DllImport("kernel32.dll")]
>
> public static extern void RtlMoveMemory(ref double dest, ref string src,
> long bytesToCopy);
>
> public static decimal convertNumber(string strValue, int varDec)
>
> {
>
> double varValue = Math.Pow(10,-1*varDec);
>
> int varLen = 8;
>
>
> RtlMoveMemory(ref varValue, ref strValue, varLen);
>
> decimal outVal = Convert.ToDecimal(Math.Round(varValue,varDec));
>
> return outVal;
>
> }
>
>
>
>
>
>


Relevant Pages

  • Re: <= 0
    ... Int is a function to convert a value to its whole number part ... What if the data type has to be Double, Fixed, 4 Decimals? ... "The form control for UnitCount is Fixed with 0 decimal points. ...
    (microsoft.public.access.formscoding)
  • Re: How do I show only the whole number w/o eliminating four decim
    ... Actually if the OP needs to do this it is better to use TRUNC since ... INT will round down to the nearest integer, ... the decimals. ...
    (microsoft.public.excel.worksheet.functions)
  • Re: How do I show only the whole number w/o eliminating four decim
    ... Good point Peo. ... INT will round down to the nearest integer, ... like -123,478.99 will return -123,479 with INT and -123,478 with TRUNC ... the decimals. ...
    (microsoft.public.excel.worksheet.functions)
  • Re: rounding decimals
    ... man4*.* wrote: ... specific number of decimals. ... For rounding we can use only int function or similar. ...
    (comp.lang.java.programmer)
  • Re: System.Math.Round bug (repost)
    ... Round(double value, int digits) ... It always seems to use the Round(decimal value, int decimals) version, no ...
    (microsoft.public.dotnet.languages.csharp)