This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes integer bit values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Reply locked New topic
Author

integer bit values

Brian Fofian
Greenhorn

Joined: Sep 14, 2005
Posts: 6
I'm having some trouble with some pretty basic stuff, and I was hoping someone could give me a hand. I need to write a program that asks the user to enter an integer and bit position. The program then needs to write out the value of the bit in that position of the integer (1 or 0). I know this sounds easy but I'm having trouble getting the correct values, especially in the bit position zero. I'm supposed to write it as a single method, and here's what i have so far:


Amatuerish at best I'm sure, but I'm getting correct values for most of my input. But if i input integer 7 at bit position 0, I'm getting that "Bit 0 of 7 is 0" when it should be set at 1. Also if there is a less complicated way of checking the value at a given bit position that might solve my problem as well.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

See response under duplicate post in Beginners forum...

http://www.coderanch.com/t/400845/java/java/bit-values-integer


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: integer bit values
 
Similar Threads
hamming code(array index out of bounds)
bit values of an integer
SoDuko puzzle
program correction
Convert decimal value to binary