473,716 Members | 2,438 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert System::UInt64 to unsigned long

What is the best way to convert a managed unsigned int64 to an
unsigned long? Basically I need to do the following:

System::UInt64 managedInt = 10;
unsigned long unmanagedInt;
unmanagedInt = managedInt;

Also it would be nice to know how to do this:

System::UInt64 managedInt;
unsigned long unmanagedInt = 10;
managedInt = unmanagedInt;

Thanks for your help.
Mike
Nov 16 '05 #1
3 9327
You do realize that a 64 bit unsigned integer like a System::UInt64 does
_not_ fir in to a 32 bit unsigned integer such as a long?

If you are sure it won't overflow, just cast:

unsigned long unmanagedInt = static_cast<uns igned long>(managedIn t);

If you want to use the same 64 bit type, just use:

unsigned long long unmangedInt = managedInt;

In physical reality there is no different between the System:: integer types
and the normal integer types in C++. Only when you take the address of them,
the type of pointer you get is different (in the 7.0 and 7.1 versions of
Visual C++, in the Whidbey version they will be identical in all respects).

Ronald Laeremans
Visual C++ team

"Mike Miller" <mm*****@bluecy press.net> wrote in message
news:f2******** *************** ***@posting.goo gle.com...
What is the best way to convert a managed unsigned int64 to an
unsigned long? Basically I need to do the following:

System::UInt64 managedInt = 10;
unsigned long unmanagedInt;
unmanagedInt = managedInt;

Also it would be nice to know how to do this:

System::UInt64 managedInt;
unsigned long unmanagedInt = 10;
managedInt = unmanagedInt;

Thanks for your help.
Mike

Nov 16 '05 #2
Ronald,
Thanks for taking the time to answer my question. I tried the
following:

System::UInt32 managedInt = 10;
unsigned long unmanagedInt = static_cast<uns igned long>(managedIn t);

When I get following compiler error:
error C2440: 'static_cast' : cannot convert from 'unsigned int __gc *'
to 'unsigned long'

I can't seem to convert between managed integer types and unmanaged
integer types.

Any help would be appreciated.
Thanks,
Mike


"Ronald Laeremans [MSFT]" <ro*****@online .microsoft.com> wrote in message news:<uI******* *******@TK2MSFT NGP12.phx.gbl>. ..
You do realize that a 64 bit unsigned integer like a System::UInt64 does
_not_ fir in to a 32 bit unsigned integer such as a long?

If you are sure it won't overflow, just cast:

unsigned long unmanagedInt = static_cast<uns igned long>(managedIn t);

If you want to use the same 64 bit type, just use:

unsigned long long unmangedInt = managedInt;

In physical reality there is no different between the System:: integer types
and the normal integer types in C++. Only when you take the address of them,
the type of pointer you get is different (in the 7.0 and 7.1 versions of
Visual C++, in the Whidbey version they will be identical in all respects).

Ronald Laeremans
Visual C++ team

"Mike Miller" <mm*****@bluecy press.net> wrote in message
news:f2******** *************** ***@posting.goo gle.com...
What is the best way to convert a managed unsigned int64 to an
unsigned long? Basically I need to do the following:

System::UInt64 managedInt = 10;
unsigned long unmanagedInt;
unmanagedInt = managedInt;

Also it would be nice to know how to do this:

System::UInt64 managedInt;
unsigned long unmanagedInt = 10;
managedInt = unmanagedInt;

Thanks for your help.
Mike

Nov 16 '05 #3
Figured it out - just being stupid on a Monday morning.
Mike
-----Original Message-----
Ronald,
Thanks for taking the time to answer my question. I tried thefollowing:

System::UInt 32 managedInt = 10;
unsigned long unmanagedInt = static_cast<uns igned long> (managedInt);
When I get following compiler error:
error C2440: 'static_cast' : cannot convert from 'unsigned int __gc *'to 'unsigned long'

I can't seem to convert between managed integer types and unmanagedinteger types.

Any help would be appreciated.
Thanks,
Mike


"Ronald Laeremans [MSFT]" <ro*****@online .microsoft.com>

wrote in message news:<uIhO9
$8*********@TK2 MSFTNGP12.phx.g bl>...
You do realize that a 64 bit unsigned integer like a System::UInt64 does _not_ fir in to a 32 bit unsigned integer such as a long?
If you are sure it won't overflow, just cast:

unsigned long unmanagedInt = static_cast<uns igned long> (managedInt);
If you want to use the same 64 bit type, just use:

unsigned long long unmangedInt = managedInt;

In physical reality there is no different between the System:: integer types and the normal integer types in C++. Only when you take the address of them, the type of pointer you get is different (in the 7.0 and 7.1 versions of Visual C++, in the Whidbey version they will be identical in all respects).
Ronald Laeremans
Visual C++ team

"Mike Miller" <mm*****@bluecy press.net> wrote in message
news:f2******** *************** ***@posting.goo gle.com...
> What is the best way to convert a managed unsigned int64 to an > unsigned long? Basically I need to do the following:
>
> System::UInt64 managedInt = 10;
> unsigned long unmanagedInt;
> unmanagedInt = managedInt;
>
> Also it would be nice to know how to do this:
>
> System::UInt64 managedInt;
> unsigned long unmanagedInt = 10;
> managedInt = unmanagedInt;
>
> Thanks for your help.
> Mike

.

Nov 16 '05 #4

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

Similar topics

1
19511
by: Fred | last post by:
Hi all, I have a nice problem. I´m trying to convert a Long to varchar2. It works when the long field doesn´t contain more than 2000 characters. How do I solve this? I´m working with Oracle 7 by the way. /Fred
3
37540
by: seema | last post by:
I am working under a Linux environment, and I want to convert a long int into a string. It looks doesnt't have a function such ltoa,itoa on stdlib. How Can I do that? I tried to work with double numbers, and convert them using fcvt function included into stdlib, but after compiled, when I run the job, I got an error: Segmentation Error (core dumped). I don't know what to do! seema
1
1326
by: John Smith | last post by:
Hello Whenever I try to set a value of a System.UInt64 I get: Dim var1 As System.UInt64 = &H18B377544DD23334 Error BC30311: Value of type 'Long' cannot be converted to 'System.UInt64'. What is the correct way?
7
38450
by: wenmang | last post by:
what is format for sprintf to convert long long integer (64 bits) to string?
0
3699
by: Madhu_TN | last post by:
Hi All, I am new to this board. I am trying to create a Crystal Report viewer into a VS C++ Dot NET 2003 app ( This uses both managed and unmanaged code). I get the following compilation error: C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include\ cstringt.h(875): error C2664: 'PtrToStringChars' : cannot convert parameter 1 from 'unsigned char *' to 'const System::String __gc *' The code segemnt is:
3
33622
by: codercoder | last post by:
It is a C++ questions: How to Convert unsigned char to CString and char *; and backward as well?
1
25463
by: bindiya182003 | last post by:
Is it posiible to convert unsigned char to char. If its possible how can I d the conversion. Please help me.
2
67276
by: mzladyd | last post by:
The source table has tbldate formated as long and I want it to be date. I've created another table and set the correct format and have tried to convert to date or char, but I continue to get error messages when I execute my Insert SQL. TO_DATE(TBLDATE) gives me this message. ORA-00932: inconsistent datatypes: expected NUMBER got LONG TO_CHAR(TBLDATE) gives me this ORA-00932: inconsistent datatypes: expected CHAR got LONG
8
4797
by: AGRAJA | last post by:
how to convert unsigned to char? Ref: http://www.thescripts.com/forum/thread477545.html how do I print without the leading ffffff (yet the result should be char*)?
0
9344
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9200
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9105
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9047
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7980
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6647
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4738
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3177
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2119
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.