Welcome to Egypt Forums Mark forums read | Egypt Main Page
Egypt Forums
Arabic Movies



Programming Languages A Place for windows applications programs and programmers .

Programming Languages Thread, java bitwise operators question in Programming , WebDesign & Development; As I understand it, if you define a variable as a byte, then by using the | operator and the ...

Short Link: http://forum.egypt.com/enforum/showthread.php?t=26762


Reply
LinkBack Thread Tools Display Modes
java bitwise operators question
 
 
Senior Member

Reply With Quote
 
Join Date: Dec 2008
Posts: 18,122
08-02-2009, 06:00 PM
 
As I understand it, if you define a variable as a byte, then by using the | operator and the >>> operator, you can update an individual bit in the designated byte. For example, in a program where b is defined as an array of bytes, you can do the...

As I understand it, if you define a variable as a byte, then by using the | operator and the >>> operator, you can update an individual bit in the designated byte.

For example, in a program where b is defined as an array of bytes, you can do the following:

b[0] = (byte)(b[0] | 0x80>>>0);

which will move a 1 in the first bit (bit 0) of byte 0.

if i do a System.out.println(b[0]) it does show a value of 128, indicating that the 0 bit was indeed set.

However, I need to not only set various bits in random bytes, I have to go back and interrogate the individual bits later to see if they are set.

I think, in some way, you use the & operator, but not sure how.

My questions are:
1. Did I set the bit properly?
2. How do I determine later if the bit was saved? I can't simply check the value of the byte, because if the first and last bit was set to 1, then the value would be 129. I need to write some kind of loop where I check each bit and interrogate it.

thanx

bob
 
 
 
Reply

Programming Languages Thread, java bitwise operators question in Programming , WebDesign & Development; As I understand it, if you define a variable as a byte, then by using the | operator and the ...

Short Link: http://forum.egypt.com/enforum/showthread.php?t=26762


Bookmarks

Tags
bitwise, java, operators, question


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump