473,396 Members | 1,923 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,396 software developers and data experts.

casting &Byte[] to long value


Hi,

I have an array of bytes like

Byte m_Data[] = new Byte[2000] ;

Byte sequences starting at a random index (4 byte aligned) should be
interpreted as unsigned long values and compared with each other.
My first try was

if ( reinterpret_cast<UInt32*>(&m_Data[20]) ==
reinterpret_cast<UInt32*>(&m_Data[104]) )
{ ... }

but the results were not always as expected (guess due to the == operator
handling the pointers).
The second try was

__value UInt32* a = reinterpret_cast<__value UInt32*>(&m_Data[20] ) ;
__value UInt32* b = reinterpret_cast<__value UInt32*>(&m_Data[104]) ;

if ( *a == *b )
{ ... }

That seems to work, but I dislike the need of extra variables (due to
performance reasons).
Has someone a really good idea about that?
Thanks

Carl

Nov 17 '05 #1
1 1439
In your first example, you are comparing two UInt32* pointers which should
never be equal. In the second example, you are getting the pointers and
then comparing what they point at, which seems more useful.

"Carl" <Ca**@discussions.microsoft.com> wrote in message
news:EB**********************************@microsof t.com...

Hi,

I have an array of bytes like

Byte m_Data[] = new Byte[2000] ;

Byte sequences starting at a random index (4 byte aligned) should be
interpreted as unsigned long values and compared with each other.
My first try was

if ( reinterpret_cast<UInt32*>(&m_Data[20]) ==
reinterpret_cast<UInt32*>(&m_Data[104]) )
{ ... }

but the results were not always as expected (guess due to the == operator
handling the pointers).
The second try was

__value UInt32* a = reinterpret_cast<__value UInt32*>(&m_Data[20] ) ;
__value UInt32* b = reinterpret_cast<__value UInt32*>(&m_Data[104]) ;

if ( *a == *b )
{ ... }

That seems to work, but I dislike the need of extra variables (due to
performance reasons).
Has someone a really good idea about that?
Thanks

Carl

Nov 17 '05 #2

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

Similar topics

4
by: Glutinous | last post by:
I've been studying this for hours, searching the www & usenet, and still can't figure out why 'each' returns an array of four key/value pairs, when it looks like just two pairs would suffice... ...
1
by: Michel Giffard LDC | last post by:
Hello everybody, we want to use a long raw field in one table, but when we put data into this field, we can't insert more than 4000 bytes. Is someone known one tips to avoid this limitation. ...
0
by: scott | last post by:
Below, I'm trying to remove the querystring name& value of "catID=12". I mananged to isolate the RESULTS part, but I need to be able to strip the querystring name and it's value, no matter if the...
7
by: The Last Gunslinger | last post by:
We have an enum: public enum EnumDays { Sun = 1, Mon = 2, ... } We can store it as a byte:
0
by: Oliver | last post by:
hi - I'm trying to set Properties dynamically (web forms). The problem is that I can't seem to set the property value based on a string - even though I know the Type of the Property. I seem...
3
by: Carl | last post by:
Hi, I have an array of bytes like Byte m_Data = new Byte ; Byte sequences starting at a random index (4 byte aligned) should be interpreted as unsigned long values and compared with each...
4
by: Josh Soref | last post by:
It seems that windows file systems can have files dated to 1617, and unfortunately if you call _findfirst/_findnext on such a directory, msvcr80d will assert. Is there some provision for...
10
by: utab | last post by:
Dear all, Can somebody direct me to some resources on the subject or explain the details in brief? I checked the FAQ but could not find or maybe missed. Regards,
9
by: andrewteg | last post by:
What is the difference between these two lines of code. I know in the second I added a & but what does that do exactly? foreach ($arr as $value) foreach ($arr as &$value) Thanks, Andrew
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:
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.