Results 1 to 7 of 7

Thread: shifts?

Threaded View

  1. #1

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    shifts?

    Does anyone know how i can figure out binary shifts without
    having to get the bit pattern? I thought i could use (number to shift) * 2^(places to shift) for << shifts and (number to shift) / 2^(places to shift) for >> shifts and >>> shifts. But the results i have been getting are just plain inconsistent. I have to take the Java Programmer certification exam soon and Sun always throws in shift questions.

    Desen't work
    64 = 0100 0000
    64 << 1 = -128
    64 * 2^1 = 128 not -128

    Works
    40 = 0010 1000
    40 << 1 = 80
    40 * 2^1 = 80

    Works
    -128 = 1000 0000
    -128 >> 2 = -32
    -128 /2^2 = -32

    Dosen't work
    -128 = 1000 0000
    -128 >>> 3 = 32
    -128/2^2 = -32 not 32

Posting Permissions

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



Click Here to Expand Forum to Full Width