bitwise « Integer « Java Data Type Q&A

Home
Java Data Type Q&A
1.bigdecimal
2.biginteger
3.bit
4.Boolean
5.byte
6.Calendar
7.cast
8.character
9.Date Time
10.Date Time Format
11.decimal
12.Development
13.double
14.enum
15.float
16.hexadecimal
17.Integer
18.Number
19.Number Format
20.primitive
21.SimpleDateFormat
22.string
23.StringBuffer
24.StringBuilder
25.StringTokenizer
26.substring
27.TimeZone
Java Data Type Q&A » Integer » bitwise 

1. How to use a bitwise operator to pass multiple Integer values into a function for Java?    stackoverflow.com

In application frameworks I keep seeing frameworks that allow you to pass in multiple Int values (generally used in place of an enum) into a function. For example:

public class Example
{ 
 ...

2. store a string in an int    stackoverflow.com

i try to store a string into an integer as follows: i read the characters of the string and every 4 characters i do this:

val = (int) ch << 24 | (int) ...

3. Why does bitwise AND of two short values result in an int value in Java?    stackoverflow.com

short permissions = 0755;
short requested = 0700;
short result = permissions & requested; 
I get a compiler error:
error possible loss of precision
found   : int
required: short
If I'm not totally wrong the ...

4. Wrapping 4 integers in a 64 bit long - java bitwise    stackoverflow.com

Alright, so I have 4 integers I want to wrap in a long. The 4 integers all contains 3 values, positioned in the first 2 bytes:

 +--------+--------+
 |xxpppppp|hdcsrrrr|
 +--------+--------+
{pppppp} represents one ...

5. A question in java.lang.Integer internal code    stackoverflow.com

While looking in the code of the method: Integer.toHexString I found the following code :

public static String toHexString(int i) {
    return toUnsignedString(i, 4);
}

private static String toUnsignedString(int i, int ...

6. Count bits used in int    stackoverflow.com

If you have the binary number 10110 how can I get it to return 5? e.g a number that tells how many bits are used? There are some likewise examples listed ...

7. 16 bit barrel shift in Java    stackoverflow.com

I'm trying to do a rotate right (barrel shift) on an int in Java, e.g.

Input:  0000 0000 0110 1001
Output: 1000 0000 0011 0100
I know I can do a right shift ...

8. Bitwise manipulation of signed integers    stackoverflow.com

int p= -6969317
int r=0xff & (p>>16);
what "r" will show and how?

9. Bitwise devision? (Changing formats of ints)    stackoverflow.com

I'm using Java. I have an integer where:

Bits 24-31 are alpha, 16-23 are red, 8-15 are green, 0-7 are blue.
I would like to change this to an int ...

10. Packing 4 bytes into an int    stackoverflow.com

Possible Duplicate:
Convert 4 bytes to int
I'm trying to pack 4 bytes into an int using some of the solutions found here, but it doesn't ...

11. Bitwise operator for simply flipping all bits in an integer?    stackoverflow.com

I have to flip all bits in a binary representation of an integer. Given:

10101
The output should be
01010
What is the bitwise operator to accomplish this when used with an integer? For ...

12. Java get first and last 2 byte from int var    stackoverflow.com

I want convert an int into 2 bytes representing that int. Probably must use bitwise and bit shifting, but I dont know what to do.

int x; /* val to convert */


// ?????????


int ...

13. bitwise addition of two integers    coderanch.com

I am having difficulty with bitwise addition of 2 integers without using arithmetic operators. My logic is suppose we have to add 3+3=6 in 2's compliment addition the logic is carry 11 (3)0000 0011 (3)0000 0011 _____________ 0000 0110 (6 ) ------------------------ I have understood the boolean logic. The task is now to write a java program without using any arithmetic ...

14. How do i convert a int to a binary with bitwise operators only?    java-forums.org

Are you asking how to get a String representation of the binary value of an int? To do that you need to look at each bit position of an int and test if its a 0 or a 1. Use the AND operator for that. Remember: 1 AND 1 = 1 1 AND 0 = 0 To look at all 32 ...

15. Bitwise shift of short integers    forums.oracle.com

I am not able to do bitwise right shift of short integers in a consistent way. For instance: short bitVal = (short)0xC007; // bitVal == -16377 short shoulBeNegative = 0xC007 >> 2; // with integers the sign bit is preserved not with short!! short shouldBePositive = (short)(bitVal >>> 2); // with integers the sign bit is lost, not so with short!! ...

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.