Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Hex printf is limited to 8 Fs
Forum Updated to NodeBB v4.3 + New Features

Hex printf is limited to 8 Fs

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 691 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bryan Kelly
    wrote on last edited by Bryan Kelly
    #1

    I am working on a long divide app and trying to see the complete value in hex. Here is the critical source.

        uint64_t dividend;
        dividend    = 0XFFFFFFFF;  // count is 9 Fs
        printf( "with 8 Fs dividend is     %llu, in hex %#020X \n", dividend, dividend );
    
        dividend    = 0XFFFFFFFFF;  // count is 9 Fs
        printf( "with 9 Fs dividend is    %llu, in hex %#020X \n", dividend, dividend );
    
        dividend    = 0XFFFFFFFFFF;  // count is 10 Fs
        printf( "with 10 Fs dividend is %llu, in hex %#020X \n", dividend, dividend );
        printf( "\n");
    

    and here is the output

    with 8 Fs dividend is     4294967295, in hex 0X0000000000FFFFFFFF
    with 9 Fs dividend is    68719476735, in hex 0X0000000000FFFFFFFF
    with 10 Fs dividend is 1099511627775, in hex 0X0000000000FFFFFFFF
    

    A 64-bit number is 8 bytes. At 2 hex characters per byte that is 16 Fs. The printf output is limited to 8 Fs.
    What is wrong with my printf statement?

    Christian EhrlicherC 1 Reply Last reply
    0
    • B Bryan Kelly

      I am working on a long divide app and trying to see the complete value in hex. Here is the critical source.

          uint64_t dividend;
          dividend    = 0XFFFFFFFF;  // count is 9 Fs
          printf( "with 8 Fs dividend is     %llu, in hex %#020X \n", dividend, dividend );
      
          dividend    = 0XFFFFFFFFF;  // count is 9 Fs
          printf( "with 9 Fs dividend is    %llu, in hex %#020X \n", dividend, dividend );
      
          dividend    = 0XFFFFFFFFFF;  // count is 10 Fs
          printf( "with 10 Fs dividend is %llu, in hex %#020X \n", dividend, dividend );
          printf( "\n");
      

      and here is the output

      with 8 Fs dividend is     4294967295, in hex 0X0000000000FFFFFFFF
      with 9 Fs dividend is    68719476735, in hex 0X0000000000FFFFFFFF
      with 10 Fs dividend is 1099511627775, in hex 0X0000000000FFFFFFFF
      

      A 64-bit number is 8 bytes. At 2 hex characters per byte that is 16 Fs. The printf output is limited to 8 Fs.
      What is wrong with my printf statement?

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by Christian Ehrlicher
      #2

      @Bryan-Kelly said in Hex printf is limited to 8 Fs:

      dividend = 0XFFFFFFFFFF; // count is 10 Fs

      You are wrong. See https://en.cppreference.com/w/cpp/language/integer_literal

      Don't know what this has to do with Qt though.

      1 Reply Last reply
      0
      • B Offline
        B Offline
        Bryan Kelly
        wrote on last edited by Bryan Kelly
        #3

        Ok, and yes I am wrong. But please be a bit more precise. That page does not use items from stdint.h and does not use printf.
        What does this have to do with Qt? Because that is what I am using and I don't see an error in my code.
        And maybe it matters to state I am using a console app.

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Your problem is plain c. As the site tells you a number is by default an integer (32 bit) when you don't add a proper suffix.

          1 Reply Last reply
          1
          • andrA Offline
            andrA Offline
            andr
            wrote on last edited by
            #5

            Try %#020lX as format. Note the 'l'.

            Christian EhrlicherC 2 Replies Last reply
            1
            • andrA andr

              Try %#020lX as format. Note the 'l'.

              Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6
              This post is deleted!
              1 Reply Last reply
              0
              • andrA andr

                Try %#020lX as format. Note the 'l'.

                Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by Christian Ehrlicher
                #7

                @andr said in Hex printf is limited to 8 Fs:

                Try %#020lX as format. Note the 'l'.

                That's correct. I was stuck in old times. The suffix for big numbers is still useful though when using the 'auto' keyword 🙂.
                So sorry, the correct link is https://cplusplus.com/reference/cstdio/printf/

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  Bryan Kelly
                  wrote on last edited by Bryan Kelly
                  #8

                  As I read it, you added a character for l, lower case L, in front of the X. When I changed the code it made no difference. I tried the character 1, digit 1, and it made the zero count to be 201, but still ended with 8 Fs, not 9 or 10.

                      uint64_t dividend;
                      dividend    = 0XFFFFFFFF;  // count is 9 Fs
                  #ifdef SHOW_DETAILS
                      printf( "with 8 Fs dividend is     %llu, in hex %#020X \n", dividend, dividend );
                  #endif
                  
                  // changed the below adding character 1, one, made the output 201 characters
                      dividend    = 0XFFFFFFFFF;  // count is 9 Fs
                  #ifdef SHOW_DETAILS
                      printf( "with 9 Fs dividend is    %llu, in hex %#0201X \n", dividend, dividend );
                  #endif
                      dividend    = 0XFFFFFFFFFF;  // count is 10 Fs
                  
                  // change below adding lower case letter L, no detecable difference.
                  #ifdef SHOW_DETAILS
                      printf( "with. 10 Fs dividend is %llu, in hex %#020lX \n", dividend, dividend );
                      printf( "\n");
                  #endif
                  
                  1 Reply Last reply
                  0
                  • B Offline
                    B Offline
                    Bryan Kelly
                    wrote on last edited by Bryan Kelly
                    #9

                    MS Bing came up with the suggestion. It adds some includes

                    #include <stdio.h>
                    #include <stdint.h>
                    #include <inttypes.h>
                    

                    and the new line

                    printf( "LINE %4i with 16 Fs dividend is %llu, in hex 0X%" PRIX64 "\n", __LINE__, dividend, dividend );
                    
                    

                    and the output

                    LINE   51 with 16 Fs dividend is 18446744073709551615, in hex 0XFFFFFFFFFFFFFFFF
                    
                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved