Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. strange hexadecimal representation

strange hexadecimal representation

Scheduled Pinned Locked Moved Solved C++ Gurus
8 Posts 5 Posters 1.5k Views 2 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.
  • R Offline
    R Offline
    r3d9u11
    wrote on last edited by r3d9u11
    #1

    Hi. I have a strange hexadecimal representation when I'm trying to display it to console:

    ...
    sout << endl << "Request: ";
    for (int i = 0; i < request.size(); i++)
        sout << " 0x" << QString::number(request[i], 16);
    sout << endl;
    ...
    

    two last value are evaluating by code:

    ...
    uint16_t u16 = getU16();
    package.append(char(u16));
    package.append(char(u16 >> 8));
    ...
    

    Data of request in debugger:
    alt text

    Output:
    alt text

    Why not just a "0xd1" and "0xfb" ?
    Why extra "ffffffffffffff" are displaying ?

    What I'm doing wrong?
    Thanks!

    jsulmJ J.HilkJ 2 Replies Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      You can simply use QByteArray::toHex().

      Regarding the extra fs - I don't know. Maybe it is a bug in Qt.

      (Z(:^

      R 1 Reply Last reply
      2
      • R r3d9u11

        Hi. I have a strange hexadecimal representation when I'm trying to display it to console:

        ...
        sout << endl << "Request: ";
        for (int i = 0; i < request.size(); i++)
            sout << " 0x" << QString::number(request[i], 16);
        sout << endl;
        ...
        

        two last value are evaluating by code:

        ...
        uint16_t u16 = getU16();
        package.append(char(u16));
        package.append(char(u16 >> 8));
        ...
        

        Data of request in debugger:
        alt text

        Output:
        alt text

        Why not just a "0xd1" and "0xfb" ?
        Why extra "ffffffffffffff" are displaying ?

        What I'm doing wrong?
        Thanks!

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @r3d9u11 said in strange hexadecimal representation:

        Why extra "ffffffffffffff" are displaying ?

        I guess because it's signed and negative and its converted to long when it is passed to QString::number

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        JKSHJ 1 Reply Last reply
        4
        • R r3d9u11

          Hi. I have a strange hexadecimal representation when I'm trying to display it to console:

          ...
          sout << endl << "Request: ";
          for (int i = 0; i < request.size(); i++)
              sout << " 0x" << QString::number(request[i], 16);
          sout << endl;
          ...
          

          two last value are evaluating by code:

          ...
          uint16_t u16 = getU16();
          package.append(char(u16));
          package.append(char(u16 >> 8));
          ...
          

          Data of request in debugger:
          alt text

          Output:
          alt text

          Why not just a "0xd1" and "0xfb" ?
          Why extra "ffffffffffffff" are displaying ?

          What I'm doing wrong?
          Thanks!

          J.HilkJ Online
          J.HilkJ Online
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @r3d9u11 said in strange hexadecimal representation:

          Why extra "ffffffffffffff" are displaying ?

          QString::number probably makes an implicit cast. However 16bytes seems unusual


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          1
          • jsulmJ jsulm

            @r3d9u11 said in strange hexadecimal representation:

            Why extra "ffffffffffffff" are displaying ?

            I guess because it's signed and negative and its converted to long when it is passed to QString::number

            JKSHJ Offline
            JKSHJ Offline
            JKSH
            Moderators
            wrote on last edited by
            #5

            @jsulm said in strange hexadecimal representation:

            @r3d9u11 said in strange hexadecimal representation:

            Why extra "ffffffffffffff" are displaying ?

            I guess because it's signed and negative and its converted to long when it is passed to QString::number

            https://bugreports.qt.io/browse/QTBUG-53706

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            R 1 Reply Last reply
            6
            • sierdzioS sierdzio

              You can simply use QByteArray::toHex().

              Regarding the extra fs - I don't know. Maybe it is a bug in Qt.

              R Offline
              R Offline
              r3d9u11
              wrote on last edited by
              #6

              @sierdzio In my current case I should to process each elements of BytesArray, however thank for useful hint (I think I will use it in future).

              1 Reply Last reply
              0
              • JKSHJ JKSH

                @jsulm said in strange hexadecimal representation:

                @r3d9u11 said in strange hexadecimal representation:

                Why extra "ffffffffffffff" are displaying ?

                I guess because it's signed and negative and its converted to long when it is passed to QString::number

                https://bugreports.qt.io/browse/QTBUG-53706

                R Offline
                R Offline
                r3d9u11
                wrote on last edited by
                #7

                @JKSH thanks!

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  r3d9u11
                  wrote on last edited by
                  #8

                  thank to all for hints and clarifications!

                  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