Results 1 to 8 of 8

Thread: question on C

  1. #1
    EmuTalk Member
    Join Date
    May 2006
    Posts
    23

    question on C

    Need help with C++(in this case it is Visual, but for this question I think it doesn't really matter):



    Suppose we have a structure called A. Consider it's element type uint32 called B. What does this line mean:

    (A.B >> 21)& 0x1f

    What does operator >> do in this case? & I would use for a pointer, but 0x1f is just a number, what & 0x1f mean? How does this construction work? I never had experience working with such a construction.


    • Advertising

      advertising
      EmuTalk.net
      has no influence
      on the ads that
      are displayed
        
       

  2. #2
    Mankind Member NoeOM's Avatar
    Join Date
    Jun 2006
    Location
    Cáceres, Spain
    Posts
    77

    Question

    the >> operator does bitwise right shift (and the << operator does left). For example, let x be a 8 bit variable with the following value

    x = 00101100

    then, after executing this piece of C (and C++) code

    x << 1;

    the value of x is:

    x = 01011000

    this operation (<<) can also be seen as a fast method of calculate some products since

    b = a << 1; is equivalent to b = a * 2;
    b = a << 2; is equivalent to b = a * 4;

    and so on, IF WE CONSIDER THAT THERE ARE NO OVERFLOW PROBLEMS (1s going out of the variable by the "left side").

    The & operator is the bitwise AND operator. After the following C statement

    c = a & b;

    the i-th bit of c is active (1) if the i-th bit of a is active AND the i-th bit of b is active. For example, let a and b be two 8 bit variables with the following values

    a = 01010101
    b = 00001111
    -------------
    a & b = 00000101

    And 0x1f is an hexadecimal number. In C, when you prefix a number with 0x, you mean the number is in hexadecimal format. 0x1f is just 31 in decimal format.


    Sorry for my bad english. I hope I have help you ... a bit

  3. #3
    EmuTalk Member
    Join Date
    May 2006
    Posts
    23
    Thanks a lot!

  4. #4
    Mankind Member NoeOM's Avatar
    Join Date
    Jun 2006
    Location
    Cáceres, Spain
    Posts
    77
    Not at all. Ask whenever you want!

  5. #5
    Plugin coder / Betatester Falcon4ever's Avatar
    Join Date
    Mar 2002
    Location
    The Netherlands
    Posts
    1,253
    *moved your thread to the programming forum, since this has nothing do to with dolphin itself...

  6. #6
    Sony battery Toasty's Avatar
    Join Date
    Dec 2004
    Location
    Oregon, U.S.A.
    Posts
    2,048
    A Wikipedia write-up on bitwise operators. There's a few other handy ones there too (XOR, NOT, OR). All of which include C/C++ examples of such operators.

  7. #7
    ????????????????????????? Doomulation's Avatar
    Join Date
    Nov 2001
    Location
    ????????????????
    Posts
    8,780
    For the record, & is the address of operator and bitwise and. & can be used to get the address of a variable, which can be used to init pointers or simply simply print the address (most commonly used for pointers). It isn't just for pointers... good to know. Well, not really, but anyway...
    Atashi wa juu-yon-sai no onna no ko! Atashi no namae wa Miizuki. Yurushiku ne!
    Nani? Atashi o shinjirimasen desu ka? Baka!
    "You're all doomed! Doomed, I say! Hehe... are we approaching the end of the world?"

    shikata ga kaite aru - "the instructions are written above"
    Need to download GoodN64 or instructions to use it? Need to check if it's a good or bad rom?
    Download: Glide64 | Hacktarux's wrapper

  8. #8
    EmuTalk Member
    Join Date
    May 2006
    Posts
    23
    Thanks

Similar Threads

  1. Question
    By aw3se4dr5 in forum Project64
    Replies: 3
    Last Post: June 1st, 2006, 11:35
  2. A small question....
    By Haisho in forum Chankast
    Replies: 0
    Last Post: February 27th, 2005, 09:23
  3. Question about ATI Rage 128 Pro
    By W|kedK|own in forum Project64
    Replies: 1
    Last Post: May 28th, 2004, 01:46
  4. Replies: 13
    Last Post: July 14th, 2003, 00:17
  5. Rom question about byteswapping
    By ashade in forum General N64 Emulation Discussion
    Replies: 1
    Last Post: August 1st, 2002, 21:52

Posting Permissions

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