Re: converting single to integer



dpb wrote:
Rick Rothstein (MVP - VB) wrote:
I do have one question to clarify my knowledge, though: does the memcopy command copy the raw bit pattern from one location to another, or does it do an implicit cast? My understanding is that it copied bit-
for-bit, so taking a memory location that was defined as a single and copying it to a location that was then interpreted as long would come up with a different value than the original Single. Is that a correct interpretation?

Yes, memcopy is precisely the former, not the latter -- it simply moves the bits from one contiguous position in memory to another without regard for any specific interpretation of what either the source or destination memory may have.

Okay, given this, of what possible use is it (as it would apply to the OP's original question)?

Well, (this is assuming I understood the question) I'm guessing it's something like he read an array that had as its first value the number of entries. I'm also guessing he got that from some non-VB code and was trying to do a straight translation...

Of course, if that were the actual case, it would be simpler to Get the first Long into an integer variable and then Get the actual array size in an appropriately-sized array.

I've also seen (and used) such tricks played with custom-built databases and similar, particularly in older FORTRAN where it was a prime way to use EQUIVALENCE to allow a particular value in memory to be interpreted as either REAL or INTEGER depending on context.

So, overall I don't know how it actually fits into OP's desired usage, but it's best guess I got as to why would want to do so... :)

I guess another use would be to simply be able to examine the contents of a FP variable in a bit-pattern mode if were trying to write a utility exploring IEEE floating point representation or somesuch...

--
.



Relevant Pages

  • Re: converting single to integer
    ... so taking a memory location that was defined as a single and copying it to a location that was then interpreted as long would come up with a different value than the original Single. ... moves the bits from one contiguous position in memory to another without regard for any specific interpretation of what either the source or destination memory may have. ... I'm guessing it's something like he read an array that had as its first value the number of entries. ...
    (microsoft.public.vb.general.discussion)
  • Comparing fields in 2 large files
    ... I am new to perl and would appreciate any suggestions as to how to do ... I'm guessing my method is not the most efficient. ... have enough memory to read the files at one time into an array. ...
    (perl.beginners)
  • Re: Is it possible to delete an element from a sorted array with O(1) time?
    ... Is it possible to delete an element from a sorted array with Otime? ... integers in constant time" as asking whether there are sequences that can ... "it is possible to add requirements such that deletion of an arbitrary ... more natural) interpretation. ...
    (comp.programming)
  • Re: Fast string operations
    ... Looping: I thought looping over arrays in managed code was "slow" ... array handling and such. ... The problem with TrimHelper is that it always returns a new string instance. ... The customer perceives this as a memory leak. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Object identity
    ... I see no justification for imposing a constraint that an interpretation ... why any number of instances in memory can't model the same human. ... you have described a 1:1 mapping and then claimed it not to ... for stating facts about named entities outside the computing space. ...
    (comp.object)