Pls explain line number 47 to 52 (binary &)

edited February 2017 in Questions about Code
        PImage steg,hide;

        int hidr =0;
        int hidg =0;
        int hidb =0;

        String hidePath,maskPath;
        //created by adam schmidt
        void setup(){

          frame.setTitle("Athaddiustego");
          hidePath = selectInput(); 
          maskPath = selectInput(); 
            hide = loadImage(hidePath);
          steg = loadImage(maskPath);

         // image(steg,0,0);
          steg.loadPixels();
          hide.loadPixels();
          for(int x =0;x<1000;x++){

            for(int y =0;y<1000;y++){

            if(x<hide.width&&y<hide.height){  
              int hidcol =hide.pixels[x+y*hide.width];
              hidr = (hidcol >> 16) & 0xFF;  // Faster way of getting red(argb)
              hidg = (hidcol >> 8) & 0xFF;   // Faster way of getting green(argb)
              hidb = hidcol & 0xFF;  //0xff==0000000000011111111
        //
              hidr=  hidr>>5;//only 3 bitsout of 8
        //
        //  
                hidg=hidg>>5;
        //
        //
                hidb=hidb>>5;
            }else{
              hidr =0;
              hidb =0;
              hidg =0;
            }

              int col =steg.pixels[x+y*steg.width];
              int r = (col >> 16) & 0xFF;  // Faster way of getting red(argb)
              int g = (col >> 8) & 0xFF;   // Faster way of getting green(argb)
              int b = col & 0xFF;          // Faster way of getting blue(argb)
        b= b&248;//11111000= 254 0&0 =0; 1&0 =0 1&1=0;// clears only last one//down 2^bit-1 from 255 per bit
        b = b|hidb;//1||0 = hidb; b= 0; | so 0&0 =0; 1&0 =1 1&1=0;
        r= r&248;//11111000= 254 0&0 =0; 1&0 =0 1&1=0;// clears only last one
        r = r|hidr;//1||0 = hidb; b= 0; | so 0&0 =0; 1&0 =1 1&1=0;
        g= g&248;//11111000= 254 0&0 =0; 1&0 =0 1&1=0;// clears only last one
        g = g|hidg;//1||0 = hidb; b= 0; | so 0&0 =0; 1&0 =1 1&1=0;
              steg.pixels[x+y*steg.width]=color(r,g,b);
              }
          }
          steg.updatePixels();

            steg.save("steg.png"); 

        }
        void draw(){




        }
Tagged:

Answers

  • Please Explain line number 47 to 52

  • Pick a number, 0 to 255

    Write it out in binary.

    Now make the last 4 binary digits all zeros.

    Convert back into base 10.

    That's what that is doing, rounding up to the nearest multiple of 8. Look up & in the reference.

  • (The comment is wrong BTW, 254 is 11111110 and will clear the last digit, but the binary number written there is 248 and will clear the last 3)

Sign In or Register to comment.