2s Complement
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1

Thread: 2s Complement

  1. #1
    Join Date
    Sep 2011
    Posts
    197

    2s Complement

    Code:
     public void handlesinglepixel(int x, int y, int pixel) {
          int alpha = (pixel >> 24) & 0xff;
          int red   = (pixel >> 16) & 0xff;
          int green = (pixel >>  8) & 0xff;
          int blue  = (pixel      ) & 0xff;
          // Deal with the pixel as necessary...
     }
    
     public void handlepixels(Image img, int x, int y, int w, int h) {
          int[] pixels = new int[w * h];
          PixelGrabber pg = new PixelGrabber(img, x, y, w, h, pixels, 0, w);
          try {
              pg.grabPixels();
          } catch (InterruptedException e) {
              System.err.println("interrupted waiting for pixels!");
              return;
          }
          if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
              System.err.println("image fetch aborted or errored");
              return;
          }
          for (int j = 0; j < h; j++) {
              for (int i = 0; i < w; i++) {
                  handlesinglepixel(x+i, y+j, pixels[j * w + i]);
              }
          }
     }

    Well I'm back again, with what would seem like an even more tasking problem ( I suppose that is almost always the reality when facing problems). I am aware '>>>' is a logical shift and '>>' is a arithmitac shift. I am under the impression '>>' is specifically used for signed 2s complement. Which (again to my understanding), is a binary number run through to equal the negative number. So, that would make me think that there shifting pixel to equal each color (E.G: the 8 index is it's level of green)? Also, I am throughly confused with 2s complement, they gave me a forumla ( I attached it ). In my mind 2s complement is just manipulating the way binary works instead of reading the sign, and then proccessing the appripriate function they can just read the number with the 'sign bit'. So all this if my assumptions are right makes sense. But, the formula below I've ran it through with -Am-1= the most significat bit (sign bit), it's just I don't know what to assign the other variables, moreover I am unaware of the function of the giant ' E '.

    To clarify:

    Question 1:
    2s complement is just manipluating the way binary handles negative variables.
    E.G
    [001 = 1] [111 = -1]
    process is INVERT then ADD ONE.
    :
    Is this all accurate ( know that I am aware 001 & 111 is not any language I just used it for the example)?

    Question 2:
    What do the variables in the forumla below represent?

    Questoin 3:
    This was just a thing I'm adding towards the end I've noticed that they sometimes use this : x = [BoBi ... b n - 1] : to represent the pixel what is this reffering to?


    P.S:
    This is a bit of a tall order, I know you folks aren't paid for this so, whatever information you can share to help would be appriciated. I am acquainted with the truth that this site isn't my personal magic 8-ball ask, and recieve, but rather the sharing of known information. So like I said any information on the subject would help. That being said note that I have used
    http://en.wikipedia.org/wiki/Two&#37;27s_complement
    http://academic.evergreen.edu/projec...am/2s_comp.htm.
    http://www.cs.cornell.edu/~tomf/note.../twoscomp.html

    * solutions *

    The giant E is a sumation, the top bit is the 'up-to' the bottom bit is the start (almost like a for statment intitilize, terminate, incriment..). I am working through the how the formula is constructed/why it works so for that I have no answer as of yet..
    Attached Images Attached Images  
    Last edited by kolt007; April 21st, 2012 at 03:33 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center