Results 1 to 6 of 6
  1. #1
    MuslimCoder is offline Senior Member
    Join Date
    Jan 2009
    Posts
    119
    Rep Power
    0

    Smile " shift " Operator ???

    Salamu Alaikum ala muslimeen,
    Hello there!!!

    I read something about the shift operator. I understood that it's faster than some of the operators in java like multiplcation, Math.pow, and division.

    Would someone explain to me what the operator does? and how (if possible) you can use it in place of the other operators???

  2. #2
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default bit shifting

    Here's a link that expalins a little:
    Bitwise and Bit Shift Operators (The Java™ Tutorials > Learning the Java Language > Language Basics)
    Some links with samples:
    SCJP Tip Line - Bit Shifting
    Java Notes: Bitwise Operators

    In the last link there's an interesting comment:
    On some older computers it was faster to use shift instead of multiply or divide.
    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  3. #3
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    7

    Default

    also note that shifting would only be considered fast if multiplying/dividing by powers of 2. doing anything more would be impractical but would make for a nice exercise.

  4. #4
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    7

    Default

    It is faster on any computer, unless your compiler has an optimizer. It's only a few nanoseconds though...
    I die a little on the inside...
    Every time I get shot.

  5. #5
    MuslimCoder is offline Senior Member
    Join Date
    Jan 2009
    Posts
    119
    Rep Power
    0

    Default

    got it :)

    The link from CJSLMAN helped alot!!!

  6. #6
    MuslimCoder is offline Senior Member
    Join Date
    Jan 2009
    Posts
    119
    Rep Power
    0

    Default

    would using a booth algorithm to create a method that multiplies using shift be faster, or slower than the multiplication operator itself???

Similar Threads

  1. Java, Military Format using "/" and "%" Operator!!
    By sk8rsam77 in forum New To Java
    Replies: 11
    Last Post: 02-26-2010, 03:03 AM
  2. Replies: 2
    Last Post: 01-24-2009, 06:56 PM
  3. Replies: 1
    Last Post: 10-20-2008, 07:35 AM
  4. <core:forEach var="" begin="+<%=j%>+">???
    By freddieMaize in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 09-27-2008, 01:20 AM
  5. "Jumble" or "Scramble" Program
    By Shadow22202 in forum Java Applets
    Replies: 8
    Last Post: 04-30-2008, 03:42 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
  •