473,434 Members | 1,818 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,434 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 1441
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
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
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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.