473,385 Members | 2,015 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,385 software developers and data experts.

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 9273
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<unsigned 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*****@bluecypress.net> wrote in message
news:f2**************************@posting.google.c om...
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<unsigned 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 unmanaged
integer types.

Any help would be appreciated.
Thanks,
Mike


"Ronald Laeremans [MSFT]" <ro*****@online.microsoft.com> wrote in message news:<uI**************@TK2MSFTNGP12.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<unsigned 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*****@bluecypress.net> wrote in message
news:f2**************************@posting.google.c om...
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::UInt32 managedInt = 10;
unsigned long unmanagedInt = static_cast<unsigned 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*********@TK2MSFTNGP12.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<unsigned 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*****@bluecypress.net> wrote in message
news:f2**************************@posting.google.c om...
> 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
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...
3
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...
1
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'. ...
7
by: wenmang | last post by:
what is format for sprintf to convert long long integer (64 bits) to string?
0
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:...
3
by: codercoder | last post by:
It is a C++ questions: How to Convert unsigned char to CString and char *; and backward as well?
1
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
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...
8
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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
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...

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.