shift « bit « Java Data Type Q&A

Java Data Type Q&A
9.Date Time
10.Date Time Format
19.Number Format
Java Data Type Q&A » bit » shift 

1. Negative logical shift

In Java, why does -32 >>> -1 = 1 ?
It's not specific to just -32. It works for all negative numbers as long as they're not too big.
I've found that
x >>> ...

2. Bitshifting Java, please explain

I'm trying to understand how bit shift works. Can someone please explain the meaning of this line:

while ((n&1)==0) n >>= 1;
where n is an integer and give me an example of ...

3. Java - Circular shift using bitwise operations

I am wondering how to implement a circular right shift by k of the bitstring represented by the int bits.

public int rtCircShift(int bits, int k)


    return bits >> ...

4. Java "Bit Shifting" Tutorial?

I would be thankfull for a good tutorial, that explain for java newbies how in java all the "bit shifting" work. I always stumble across it, but never understood how it ...

5. Reversing a Number using bitwise shift

I am trying to find a way to reverse a number without

  1. Converting it to a string to find the length
  2. Reversing the string and parsing it back
  3. Running a separate loop ...

6. Bit shift in Java

May be I am too tired.
Why dont't the following display the same value?

int x = 42405;
System.out.println(x << 8);  
System.out.println((x &0x00ff) << 8);  
The lower bits should be ...

7. bitwise shift operations

Can someone quickly explain to me the behavior of bitwise shift operations. For example: 13 >> 1 = 6 13 >> 2 = 3 13 >> 3 = 1 I understand the logic in how these bits are shifted and the end result in these cases. I also understand why if you shift over 3 then you should get 0 back. ...

8. Division by bit shift

I read that performance can be improved by using bit shifting in place of division. Is it possible to do this with denominators other than 2? For example, say I want to divide 2 by 3. (ie. 2/3) What about 3/4? How would I do this and would I get the same performance benefits? Thanks, Drew

9. Bit Shifting Question

10. what does these bitwise shift doing here ??

Hello Everybody, I was trying some code given n net for reading BMP file and saving into another format and not able to understand the following code which is converting int into Dword. My Int value is 64 which I am trying to convert.:- /* * * intToDWord converts an int to a double word, where the return * value is ...

11. Bitwise and Shift

I once had the job of maintaining code written by a quintescent heads-down programmer. A brilliant guy, but a little sparse on the comments. That is, he never wrote any at all. Even his variables tended to be x1, x2, x3, etc. So I'm looking for this place where the user answers a yes/no question, where Y and y were the ...

12. Bit Shifting

Well, the classic usage is packing multiple values into an int. I know this kind of stuff makes people go " ", but if you're going to have two million objects which each need ten state values each of which can have three different value, you can use ten integers (80 megabytes total) to store them, or one integer (8 megabytes ...

13. Doubt with bit shifting,Please help

I was learning about right shift operator in one of the corey's links Right shifting the positive number is ok,but with negative number, I had a doubt.Let me interpret what I have understood. With respect to the most significant number in the right side of the binary number to be shifted,if it is 0 then the number is positive and ...

14. shifting bits of -1

That's because when you shift an int 32 times, it will really be shifted 0 times instead of 32 times. Section 15.19 of the Java Language Specification explains this: If the promoted type of the left-hand operand is int, only the five lowest-order bits of the right-hand operand are used as the shift distance. It is as if the right-hand operand ...

15. bit shift question.

Am I doing this correct ? byte[] buffer = new byte[16 << 16]; int bytesRead = 0; while((bytesRead = != -1) { //writing ... } . . . . . . . bos = new BufferedOutputStream(fos, 1024*2048); while((bytesRead = != -1) { // writing... } I wanted to confirm if I am using the bit shift operators correctly. 1) ...

16. Bit Wise and Bit Shift error

Friends, I got two methods to make a conversion from byte array to long and the other to make from long to byte array, the problem is that when i use a number with a negative signal the code broken and the result is not the expected, so, if someone can give me a help i'll be thankful so much cause ...

17. bit shifting example

18. Bitshifting doesn't shift bits?

19. Multiply, or shift bits?

Hey, just a quicky! Let's say I have a program that needs to be fast, and let's say that I want to multiply/divide something with a power of two (2^1, 2^2, ...). Would it be faster to carry out the multiplication, for example n * 2, or would it be faster to shift the bits one step to the left, n ...

20. Thoughts about how to bit shift large amounts of data

Hello! I'm new to the forums , so go easy, eh? I'm trying to write an application that does the following: Recieve UDP Packet Sequence with remainder of previous packet Find start bits, read following 100 bytes Reformat these bytes from 12 bits -> 16 bits Rebroadcast 512 byte segments Let me explain the situation further. Each UDP packet comes in ...

21. Bit wise shifting in J2SE

22. Shifting Bits

Hi, Lets say I have two ints intOne = 97 intTwo = 98 Which both hold a byte value for ascii representation letter a and b. Then the following line int k = (intOne<<8)+intTwo; What i want to achieve from this line is to add a and b to create the string ab. The value for k is 24930, id like ...

23. Bitwise shifting

24. Bit Shifting vs Multiplication

25. Problem with bit shifting

26. Bitwise Right Shift vs Divide by 2

Something that just pondered across my mind. Bitwise operators have their uses, and I've always known about right/left shifting to divide/multiply by 2. I recently did some empirical analysis on an algorithm using this technique, and I had to iterate it over a trillion times before I started seeing any timing differences, and even then they were in the order of ...

27. Issue with bit shifting

I have a question about bit shifting. When I attempt to shift 32 bit on a int value, the output is the same value. It doesn't matter if I try to make a rigth or left shifting. It also hapend when I make 64 bit shifting on a long value. I supposed it should be 0. This is the code I'm ...

28. bits shifting

29. Bit shifting

30. Bit Shifting Help

31. bit shifting, card value brain teaser...

Hi, I have been experimenting with converting some code from c to java. I used cactus kevs card hand analyser as my base unit and having converted it, have been messing around with the algorithms for the fun of it! I have one thing I can't quite work out though. This is the card value layout, he uses a 32 bit ...

32. problem shifting bits

Hi there, I want to pass over some parameters which are location information. Eventually i want these to be stored as short.. but I have some problems for values like 41,200 which is 10100000 11110000 This value is stored in a byte[], and then send over through sockets. The value is stored in such array as: -96, -16 I use a ...  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.