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. variables

variables

Scheduled Pinned Locked Moved C / C++ / MFC
questioncssdata-structurestutorial
7 Posts 4 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.
  • T Offline
    T Offline
    Timothy Grabrian
    wrote on last edited by
    #1

    How can I simplify this: grid[x][y] == 0 ? grid[x][y] = 1 : grid[x][y] = 0; I was thinking that I could make a pointer (or address) to that part of the array, then like shift the bits or something (each part of the array is a BYTE), but I couln't figure out how to do it. Any ideas? thanks

    T D T 3 Replies Last reply
    0
    • T Timothy Grabrian

      How can I simplify this: grid[x][y] == 0 ? grid[x][y] = 1 : grid[x][y] = 0; I was thinking that I could make a pointer (or address) to that part of the array, then like shift the bits or something (each part of the array is a BYTE), but I couln't figure out how to do it. Any ideas? thanks

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      grid[x][y] == 0 ? grid[x][y] = 1 : grid[x][y] = 0; means basicly :

      if (grid[x][y] == 0) {
      grid[x][y] = 1;
      }
      else {
      grid[x][y] = 0;
      }


      TOXCCT >>> GEII power
      [toxcct][VisualCalc]

      T 1 Reply Last reply
      0
      • T toxcct

        grid[x][y] == 0 ? grid[x][y] = 1 : grid[x][y] = 0; means basicly :

        if (grid[x][y] == 0) {
        grid[x][y] = 1;
        }
        else {
        grid[x][y] = 0;
        }


        TOXCCT >>> GEII power
        [toxcct][VisualCalc]

        T Offline
        T Offline
        Timothy Grabrian
        wrote on last edited by
        #3

        Oh, yeah, I wasn't talking simplifying like that, I meant something like BYTE GridPos = &grid[x][y];//might not even need this GridPos &= GridPos; (I know thats wrong, but thats what I'm thinking it should look like, just diffrent opperators)

        M T 2 Replies Last reply
        0
        • T Timothy Grabrian

          Oh, yeah, I wasn't talking simplifying like that, I meant something like BYTE GridPos = &grid[x][y];//might not even need this GridPos &= GridPos; (I know thats wrong, but thats what I'm thinking it should look like, just diffrent opperators)

          M Offline
          M Offline
          Maximilien
          wrote on last edited by
          #4

          don't ... it looks ugly, it's unreadable ... I suggest keeping it as simple as possible and let the compiler do the work for you.


          Maximilien Lincourt Your Head A Splode - Strong Bad

          1 Reply Last reply
          0
          • T Timothy Grabrian

            Oh, yeah, I wasn't talking simplifying like that, I meant something like BYTE GridPos = &grid[x][y];//might not even need this GridPos &= GridPos; (I know thats wrong, but thats what I'm thinking it should look like, just diffrent opperators)

            T Offline
            T Offline
            toxcct
            wrote on last edited by
            #5

            ok, if we consider the test (== 0) MUST be performed befor doing anything on the matrix, the code is not very "simplifying". if not, i consider that, if grid[x][y] equal 0, it must be set to 1, and if it equals 1, it must be set to 0. it is then easy to do that with the bitwise not **~=** operator :

            grid[x][y] ~= grid[x][y];

            according to the table :

            ~ 1 0

            = 0 1


            TOXCCT >>> GEII power
            [toxcct][VisualCalc]

            1 Reply Last reply
            0
            • T Timothy Grabrian

              How can I simplify this: grid[x][y] == 0 ? grid[x][y] = 1 : grid[x][y] = 0; I was thinking that I could make a pointer (or address) to that part of the array, then like shift the bits or something (each part of the array is a BYTE), but I couln't figure out how to do it. Any ideas? thanks

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              I'm not sure what is non-simple about what you already have, but this is an alternative: grid[x][y] = ! grid[x][y];


              "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

              1 Reply Last reply
              0
              • T Timothy Grabrian

                How can I simplify this: grid[x][y] == 0 ? grid[x][y] = 1 : grid[x][y] = 0; I was thinking that I could make a pointer (or address) to that part of the array, then like shift the bits or something (each part of the array is a BYTE), but I couln't figure out how to do it. Any ideas? thanks

                T Offline
                T Offline
                Timothy Grabrian
                wrote on last edited by
                #7

                Thanks all, I got it.

                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