473,856 Members | 1,630 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 9341
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
19536
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
37579
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
1332
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
38465
by: wenmang | last post by:
what is format for sprintf to convert long long integer (64 bits) to string?
0
3707
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
33669
by: codercoder | last post by:
It is a C++ questions: How to Convert unsigned char to CString and char *; and backward as well?
1
25709
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
67390
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
4807
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
10697
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
10786
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
10389
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
9532
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...
0
7097
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5762
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4578
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
2
4175
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3202
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.