Thread: what do these operations do?

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    17

    what do these operations do?

    I am sorry if this is a stupid question but I have looked around and can not find the answer anywhere.

    What do these two operations do?

    a |= b

    and

    a=a>>1
    When i find myself in times of trouble. mother mary comes to me, speaking words of wisdom, let it be C

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Read the Bitwise Operation FAQ. All the information you need is already written up there.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    People Love Me
    Join Date
    Jan 2003
    Posts
    412
    Quote Originally Posted by the_head
    I am sorry if this is a stupid question but I have looked around and can not find the answer anywhere.

    What do these two operations do?

    a |= b

    and

    a=a>>1
    Those are bitwise operations. The first adds two variables or constants with bitwise OR, and the second shifts a value a certain number of bits. If you don't know how to read binary code, then they're rather useless to you.

    Say a=3 and b=5

    Code:
    //Not actually code, but whatever.
     0011
    +0101   //Add using bitwise OR
    =0111 //Our result is 7.
    And the second operation would shift A's bits over 1 place to the right.

    0011 >> 1 = 0001
    So 3>>1 = 1.
    Last edited by Krak; 01-29-2005 at 02:40 PM.

  4. #4
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    The first adds two variables or constants with bitwise OR
    Very poor choice of words here. OR is not addition, as such it doesn't "add" them together.

  5. #5
    People Love Me
    Join Date
    Jan 2003
    Posts
    412
    Quote Originally Posted by Thantos
    Very poor choice of words here. OR is not addition, as such it doesn't "add" them together.
    True..I kinda like to think of it as "adding with OR"...rather than calling it "OR'ing" them together, eh?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. doing floating operations using integer operations
    By ammalik in forum C Programming
    Replies: 10
    Last Post: 08-15-2006, 04:30 AM
  2. Matrix and vector operations on computers
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 05-11-2004, 06:36 AM
  3. String Class Operations
    By Aidman in forum C++ Programming
    Replies: 10
    Last Post: 04-06-2003, 02:29 PM
  4. Floating point operations
    By kjc197 in forum C Programming
    Replies: 5
    Last Post: 02-08-2003, 06:44 AM