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. Can anybody explain me below statement ?
Forum Updated to NodeBB v4.3 + New Features

Can anybody explain me below statement ?

Scheduled Pinned Locked Moved Solved C++ Gurus
6 Posts 3 Posters 721 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.
  • Q Offline
    Q Offline
    Qt embedded developer
    wrote on last edited by Qt embedded developer
    #1

    sscanf(strValue + 2i, "%02x", &bytearray[i]);

    where strValue = " B7D2E40383FB42397357C80DF39B8CF0";
    & bytearray declared like below :
    unsigned char bytearray[20];

    here strValue [0] and strValue [1] both are combinedly get store into bytearray[0].

    above statement is not set into my mind. i want to know how it combine 2 string char into one byte.

    i know that second argument of sscanf is doing this but i not know what exactly %02x do ?

    JonBJ 1 Reply Last reply
    1
    • Q Qt embedded developer

      sscanf(strValue + 2i, "%02x", &bytearray[i]);

      where strValue = " B7D2E40383FB42397357C80DF39B8CF0";
      & bytearray declared like below :
      unsigned char bytearray[20];

      here strValue [0] and strValue [1] both are combinedly get store into bytearray[0].

      above statement is not set into my mind. i want to know how it combine 2 string char into one byte.

      i know that second argument of sscanf is doing this but i not know what exactly %02x do ?

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by JonB
      #2

      @Qt-embedded-developer said in Can anybody explain me below statement ?:

      %02x

      This tells it to read 2 characters, treat it as a (2-digit) hexadecimal number-string, convert to number (0x00--0xff) and store the number as (one byte in) bytearray[i].

      If you put it inside an i loop it will go along reading 2 characters at a time from strValue, converting them to a single byte to be stored at bytearray[i].

      1 Reply Last reply
      4
      • Q Offline
        Q Offline
        Qt embedded developer
        wrote on last edited by
        #3

        @JonB how to do of same thing for (2-digit) hexadecimal number-string , treat it as read 2 characters

        jsulmJ 1 Reply Last reply
        0
        • Q Qt embedded developer

          @JonB how to do of same thing for (2-digit) hexadecimal number-string , treat it as read 2 characters

          jsulmJ Online
          jsulmJ Online
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Qt-embedded-developer said in Can anybody explain me below statement ?:

          how to do of same thing for (2-digit) hexadecimal number-string , treat it as read 2 characters

          Please rephrase, it is really hard to understand

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

          Q 1 Reply Last reply
          1
          • jsulmJ jsulm

            @Qt-embedded-developer said in Can anybody explain me below statement ?:

            how to do of same thing for (2-digit) hexadecimal number-string , treat it as read 2 characters

            Please rephrase, it is really hard to understand

            Q Offline
            Q Offline
            Qt embedded developer
            wrote on last edited by
            #5

            @jsulm how to split this hexadecimal number string into 2 separate char ?
            hexnumber char array[ 0] char array[1]
            0xbd --> b d

            JonBJ 1 Reply Last reply
            0
            • Q Qt embedded developer

              @jsulm how to split this hexadecimal number string into 2 separate char ?
              hexnumber char array[ 0] char array[1]
              0xbd --> b d

              JonBJ Online
              JonBJ Online
              JonB
              wrote on last edited by
              #6

              @Qt-embedded-developer
              If you already have the two chars in "char array[ 0] char array[1]" then you already have your answer.
              If you start with a number then use e.g. QString,arg(yournum, 2, 16, 0), see https://doc.qt.io/qt-6/qstring.html#arg-3.

              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