Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Using hex in an array and "scanning" for it fails.

Using hex in an array and "scanning" for it fails.

Scheduled Pinned Locked Moved C / C++ / MFC
databasedata-structureshelp
5 Posts 3 Posters 0 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.
  • V Offline
    V Offline
    Vaclav_
    wrote on last edited by
    #1

    I am going nuts with this test code. Two dimensional array and my test objective is to find matching first element in the arrays. It works fine "scanning " for 0xA as it should , goes crazy when I try to look for 0xB0. I hope is is something stupid I am overlooking. Hope any extra pairs of eyes will spot the problem.

    #define COMMAND_LIST 16
    int8_t ILI9341_Command_List[][COMMAND_LIST] = {
    { 0 },
    { 1 },
    { 4 },
    { 6, 7 , 8 },
    {7},
    {0xA,8,9,10,11,12},
    {0xB0,8,9,10,11,12},
    {9}
    };

    uint8_t ProcessCommand = 0xB0; // 0xA work fine 0xB0 fails
    int index = 0;
    do {
    cout << "SCAN ProcessCommand " << hex << +ProcessCommand << "@ index "
    << dec << +index << endl;

    } while (ILI9341\_Command\_List\[index++\]\[0\] != ProcessCommand);
    
    P 1 Reply Last reply
    0
    • V Vaclav_

      I am going nuts with this test code. Two dimensional array and my test objective is to find matching first element in the arrays. It works fine "scanning " for 0xA as it should , goes crazy when I try to look for 0xB0. I hope is is something stupid I am overlooking. Hope any extra pairs of eyes will spot the problem.

      #define COMMAND_LIST 16
      int8_t ILI9341_Command_List[][COMMAND_LIST] = {
      { 0 },
      { 1 },
      { 4 },
      { 6, 7 , 8 },
      {7},
      {0xA,8,9,10,11,12},
      {0xB0,8,9,10,11,12},
      {9}
      };

      uint8_t ProcessCommand = 0xB0; // 0xA work fine 0xB0 fails
      int index = 0;
      do {
      cout << "SCAN ProcessCommand " << hex << +ProcessCommand << "@ index "
      << dec << +index << endl;

      } while (ILI9341\_Command\_List\[index++\]\[0\] != ProcessCommand);
      
      P Offline
      P Offline
      Peter_in_2780
      wrote on last edited by
      #2

      because 0xb0 is negative in 8 bits? You are comparing a uint8_t (unsigned) with an int8_t (signed)

      Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012

      V 1 Reply Last reply
      0
      • P Peter_in_2780

        because 0xb0 is negative in 8 bits? You are comparing a uint8_t (unsigned) with an int8_t (signed)

        Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012

        V Offline
        V Offline
        Vaclav_
        wrote on last edited by
        #3

        Thank you. I knew I was getting too tired and that it was something STUPID I missed.

        CPalliniC 1 Reply Last reply
        0
        • V Vaclav_

          Thank you. I knew I was getting too tired and that it was something STUPID I missed.

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #4

          Compiling with all the warnings enabled (e.g. -Wall option, for g++) would help.

          In testa che avete, signor di Ceprano?

          V 1 Reply Last reply
          0
          • CPalliniC CPallini

            Compiling with all the warnings enabled (e.g. -Wall option, for g++) would help.

            V Offline
            V Offline
            Vaclav_
            wrote on last edited by
            #5

            Thanks, I'll check that. I do not want to make excuses , but I think I just copied the test code and missed the "u" , but I did get some - (minus) output when it went crazy.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups