Thread: [Dev-C++] Can I handle 64 bits with unsigned long long int ?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Roberto R. <rob...@ar...> - 2003-04-05 23:10:58
|
Hi all,
Can I handle 64 bits numbers with unsigned long long ?
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
unsigned long long int D0,D1 ;
int main(int argc, char *argv[])
{
D0 = 0;
D1 = 0xffffffffffff; /* I put first unsigned long int, compiler
alerts about truncated number...) */
gotoxy(1,9);printf ("Num hexa : ");
scanf ("%x",&D0); /*can handle whatever up to 32 bits*/
gotoxy(1,11);printf ("Dec0: %lu\nDec1: %lu\n\n", D0, D1);
getchar(); getchar();
return 0;
}
/*
Results:
Dec0 : 4294967295 mean ok if I put just up to 0xffffffff 32bits
Dec1 : 0 ??
*/
Why is ever truncated in 32 bits, how can handle long long to get up to
64 bits numbers ?
Thanks in advance
Roberto
|
|
From: Ioannis V. <iv...@em...> - 2003-04-06 09:25:46
|
Question about C99. That is a first! See below:
> -----Original Message-----
> From: dev...@li...=20
> [mailto:dev...@li...] On Behalf=20
> Of Roberto Ricardi
> Sent: Sunday, April 06, 2003 2:11 AM
> To: 'Dev-C++ -Users-List'
> Subject: [Dev-C++] Can I handle 64 bits with unsigned long long int ?
>=20
>=20
> Hi all,
>=20
> Can I handle 64 bits numbers with unsigned long long ?
>=20
> #include <stdio.h>
> #include <stdlib.h>
> #include <conio.h>
>=20
> unsigned long long int D0,D1 ;
> =20
> int main(int argc, char *argv[])
> {
> D0 =3D 0;
> D1 =3D 0xffffffffffff; /* I put first unsigned long int, compiler=20
> alerts about truncated number...) */
> gotoxy(1,9);printf ("Num hexa : ");
> scanf ("%x",&D0); /*can handle whatever up to 32 bits*/
> gotoxy(1,11);printf ("Dec0: %lu\nDec1: %lu\n\n", D0, D1);
> =20
> getchar(); getchar();
> return 0;
> }
> /*
> Results:
>=20
> Dec0 : 4294967295 mean ok if I put just up to 0xffffffff 32bits
> Dec1 : 0 ??
> */
>=20
> Why is ever truncated in 32 bits, how can handle long long to=20
> get up to=20
> 64 bits numbers ?
unsigned long long is not guaranteed to be 64-bit. If you want an =
unsigned
integral type to be at least 64-bit, you have to do:
#include <stdint.h>
// ...
uint_least64_t D0, D1;
// ...
which is a typedef of the closest to 64-bit type provided by platform
(closest from above, that is if unsigned long is 32 bit and unsigned =
long
long is 128 bit for example, the typedef will be of unsigned long long).
I read it straight from the standard. I do not know whether MINGW has
implemented it (and as far as I know these facilities are "optional", if =
the
platform doesn't support >=3D64 bit, will not have the above type =
naturally).
By the way, have you got any book regarding C99? If yes, can you please =
tell
me which?
Ioannis Vranos
=20
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL: http://run.to/noicys
Anti-racism movement: http://www.positive-youthfoundation.org
Iraq Peace Pledge: http://www.peacepledge.org
|
|
From: Roberto R. <rob...@ar...> - 2003-04-12 03:25:04
|
Hi all,
Sorry was not here by the while. IM learn about C & C++ standares just
here, at dev-cpp list. Im not a expert programmer, using I64 I can
handle 64 bits hexa friendly. I use it to work with comunications
protocols, industrial controls, etc.
....
scanf ("%I64x",&Dato);
gotoxy(1,11);printf ("Dec0: %I64u\nDec1: %I64u\n\n", Dato, Dato1);
....
Will try to ask some friends about C99 books :)
Thanks Ioannis
Roberto
Ioannis Vranos wrote:
>Question about C99. That is a first! See below:
>
>
>
>
>
>>-----Original Message-----
>>From: dev...@li...
>>[mailto:dev...@li...] On Behalf
>>Of Roberto Ricardi
>>Sent: Sunday, April 06, 2003 2:11 AM
>>To: 'Dev-C++ -Users-List'
>>Subject: [Dev-C++] Can I handle 64 bits with unsigned long long int ?
>>
>>
>>Hi all,
>>
>>Can I handle 64 bits numbers with unsigned long long ?
>>
>>#include <stdio.h>
>>#include <stdlib.h>
>>#include <conio.h>
>>
>>unsigned long long int D0,D1 ;
>>
>>int main(int argc, char *argv[])
>>{
>> D0 = 0;
>> D1 = 0xffffffffffff; /* I put first unsigned long int, compiler
>>alerts about truncated number...) */
>> gotoxy(1,9);printf ("Num hexa : ");
>> scanf ("%x",&D0); /*can handle whatever up to 32 bits*/
>> gotoxy(1,11);printf ("Dec0: %lu\nDec1: %lu\n\n", D0, D1);
>>
>> getchar(); getchar();
>> return 0;
>>}
>>/*
>>Results:
>>
>>Dec0 : 4294967295 mean ok if I put just up to 0xffffffff 32bits
>>Dec1 : 0 ??
>>*/
>>
>>Why is ever truncated in 32 bits, how can handle long long to
>>get up to
>>64 bits numbers ?
>>
>>
>
>
>unsigned long long is not guaranteed to be 64-bit. If you want an unsigned
>integral type to be at least 64-bit, you have to do:
>
>
>#include <stdint.h>
>
>// ...
>
>uint_least64_t D0, D1;
>
> // ...
>
>
>
>which is a typedef of the closest to 64-bit type provided by platform
>(closest from above, that is if unsigned long is 32 bit and unsigned long
>long is 128 bit for example, the typedef will be of unsigned long long).
>
>
>I read it straight from the standard. I do not know whether MINGW has
>implemented it (and as far as I know these facilities are "optional", if the
>platform doesn't support >=64 bit, will not have the above type naturally).
>
>
>By the way, have you got any book regarding C99? If yes, can you please tell
>me which?
>
>
>
>
>Ioannis Vranos
>
>* Programming pages: http://www.noicys.freeurl.com
>* Alternative URL: http://run.to/noicys
>
>
>Anti-racism movement: http://www.positive-youthfoundation.org
>Iraq Peace Pledge: http://www.peacepledge.org
>
>
>
>
>-------------------------------------------------------
>This SF.net email is sponsored by: ValueWeb:
>Dedicated Hosting for just $79/mo with 500 GB of bandwidth!
>No other company gives more support or power for your dedicated server
>http://click.atdmt.com/AFF/go/sdnxxaff00300020aff/direct/01/
>_______________________________________________
>Dev-cpp-users mailing list
>Dev...@li...
>TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
>https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
>
>
|
|
From: Ioannis V. <iv...@em...> - 2003-04-06 09:36:29
|
Question about C99. That is a first! See below:
> -----Original Message-----
> From: dev...@li...=20
> [mailto:dev...@li...] On Behalf=20
> Of Roberto Ricardi
> Sent: Sunday, April 06, 2003 2:11 AM
> To: 'Dev-C++ -Users-List'
> Subject: [Dev-C++] Can I handle 64 bits with unsigned long long int ?
>=20
>=20
> Hi all,
>=20
> Can I handle 64 bits numbers with unsigned long long ?
>=20
> #include <stdio.h>
> #include <stdlib.h>
> #include <conio.h>
>=20
> unsigned long long int D0,D1 ;
> =20
> int main(int argc, char *argv[])
> {
> D0 =3D 0;
> D1 =3D 0xffffffffffff; /* I put first unsigned long int, compiler=20
> alerts about truncated number...) */
> gotoxy(1,9);printf ("Num hexa : ");
> scanf ("%x",&D0); /*can handle whatever up to 32 bits*/
> gotoxy(1,11);printf ("Dec0: %lu\nDec1: %lu\n\n", D0, D1);
> =20
> getchar(); getchar();
> return 0;
> }
> /*
> Results:
>=20
> Dec0 : 4294967295 mean ok if I put just up to 0xffffffff 32bits
> Dec1 : 0 ??
> */
>=20
> Why is ever truncated in 32 bits, how can handle long long to=20
> get up to=20
> 64 bits numbers ?
unsigned long long is not guaranteed to be 64-bit. If you want an =
unsigned
integral type to be at least 64-bit, you have to do:
#include <stdint.h>
// ...
uint_least64_t D0, D1;
// ...
which is a typedef of the closest to 64-bit type provided by platform
(closest from above, that is if unsigned long is 32 bit and unsigned =
long
long is 128 bit for example, the typedef will be of unsigned long long).
I read it straight from the standard. I do not know whether MINGW has
implemented it (and as far as I know these facilities are "optional", if =
the
platform doesn't support >=3D64 bit, will not have the above type =
naturally).
By the way, have you got any book regarding C99? If yes, can you please =
tell
me which?
Ioannis Vranos
=20
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL: http://run.to/noicys
Anti-racism movement: http://www.positive-youthfoundation.org
Iraq Peace Pledge: http://www.peacepledge.org
|