+ Reply to Thread
Results 1 to 2 of 2

Thread: How to print 64bit integer in different platform?

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    48

    How to print 64bit integer in different platform?

    Hi all,

    I am new to 64-bit programming and I have a question, how to print 64bit integer in different platform?

    Thanks.

  2. #2
    Hi,

    Below example displays printing 64bit int on different platform:

    Code:
    void PrintLargeInteger()
    {
    	//In, MS VS 2005 and above, below works fine.
    	__int64 nLargeInteger = 120123410234122343 ;
    
    	char szLargeInteger[100] = "" ;
    	sprintf(szLargeInteger, "%I64d", nLargeInteger) ;
    
    	unsigned long long ullBigInteger = 120123410234122343 ;
    	sprintf(szLargeInteger, "%llu", ullBigInteger) ;
    
    	//For linux:
    	//Use uint64_t defined in <stdint.h> and "%llu" or "%lld"in printf
    	//Example:
    	//unsigned long long ullBigInteger = 120123410234122343 ;
    	//sprintf(szLargeInteger, "%llu", ullBigInteger) ;
    }

    So it is better to use "%llu" and "%lld".

    Regards

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts