Thread: how to print 64 bit unsigned long long in hexadecimal

  1. #1
    Registered User
    Join Date
    Aug 2016
    Posts
    4

    how to print 64 bit unsigned long long in hexadecimal

    I have a problem in printing a 64 bit unsigned long long to hexadecimal number

    here is the code i have given
    Code:
    /#include<stdio.h>
    #include<conio.h>
    #include<stdint.h>
    void main()
    {clrscr();
    unsigned long long state=0xffffffffffffffff;
    printf("%016llx",state);
    getch();
    }
    expected value:
    ffffffffffffffff
    printed output:
    00000000ffffffff
    /

    can anyone solve this issue

  2. #2
    Registered User
    Join Date
    Sep 2015
    Posts
    31
    The max value for 64 bit is 7fffffffffffffff

  3. #3
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    The same code prints the correct value for me. Maybe, just maybe, you compiler is TurboCrap and "unsigned long long" is 32-bit wide? If not, try adding "LL" as a suffix to the hex value.

    Quote Originally Posted by billboardplus View Post
    The max value for 64 bit is 7fffffffffffffff
    Not if it's unsigned though.
    Devoted my life to programming...

  4. #4
    Registered User
    Join Date
    Aug 2016
    Posts
    4
    it is showing error in turbo c++ compiler

  5. #5
    Registered User
    Join Date
    Aug 2016
    Posts
    4
    but atleast it should have print other 15 hexa values but it is printing only 32 bit word

  6. #6
    Registered User
    Join Date
    Aug 2016
    Posts
    4
    only 32 bit decimal is acceped by unsigned long long and so it is printing 8 hexa values what can i do

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by kalai View Post
    it is showing error in turbo c++ compiler
    There's your biggest issue. Get a compiler that didn't stop evolving 1993. Get a modern compiler such as clang, gcc or Visual Studio.
    Then print using C++: std::cout << std::hex << my64bitvar;
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Generate unsigned long long type random numbers
    By patishi in forum C Programming
    Replies: 27
    Last Post: 09-11-2013, 09:03 PM
  2. problem while printing unsigned long long int
    By Dedalus in forum C Programming
    Replies: 3
    Last Post: 03-08-2012, 04:44 AM
  3. Replies: 1
    Last Post: 10-11-2010, 01:53 AM
  4. unsigned long long division print
    By Kempelen in forum C Programming
    Replies: 4
    Last Post: 01-30-2009, 10:03 AM
  5. unsigned long long to string conversion
    By Wiretron in forum C++ Programming
    Replies: 6
    Last Post: 12-21-2007, 04:02 AM

Tags for this Thread