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
QtWS25 Last Chance

Hex printf is limited to 8 Fs

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 562 Views
  • 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 4 Jul 2024, 03:00 last edited by Bryan Kelly 7 Apr 2024, 03:02
    #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?

    C 1 Reply Last reply 4 Jul 2024, 04:19
    0
    • B Bryan Kelly
      4 Jul 2024, 03:00

      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?

      C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 4 Jul 2024, 04:19 last edited by Christian Ehrlicher 7 Apr 2024, 04:19
      #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 4 Jul 2024, 04:55 last edited by Bryan Kelly 7 Apr 2024, 04:56
        #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
        • C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 4 Jul 2024, 05:16 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
          • A Offline
            A Offline
            andr
            wrote on 4 Jul 2024, 05:20 last edited by
            #5

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

            C 2 Replies Last reply 4 Jul 2024, 05:26
            1
            • A andr
              4 Jul 2024, 05:20

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

              C Offline
              C Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 4 Jul 2024, 05:26 last edited by
              #6
              This post is deleted!
              1 Reply Last reply
              0
              • A andr
                4 Jul 2024, 05:20

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

                C Offline
                C Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on 4 Jul 2024, 05:42 last edited by Christian Ehrlicher 7 Apr 2024, 05:46
                #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 4 Jul 2024, 21:23 last edited by Bryan Kelly 7 Apr 2024, 21:25
                  #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 5 Jul 2024, 00:22 last edited by Bryan Kelly 7 May 2024, 00:23
                    #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

                    1/9

                    4 Jul 2024, 03:00

                    • Login

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