| Author |
Help me with byte and bits
|
John Cobra
Greenhorn
Joined: Sep 06, 2011
Posts: 3
|
|
Hi all,
i have a problem... and maybe you can help
in the end i need a Byte with the "0" and "1" in the position that i want..
it means...
if (...){
set in the position x the value "1"
}
so in the begin i need a byte like 00000000
and then i start setting "1" in each position...
how can i do this??
any good soluction?
thanks a lot.
|
 |
John Cobra
Greenhorn
Joined: Sep 06, 2011
Posts: 3
|
|
If i have string like
string bits = "00010010";
this will work?
byte bits = Byte.parseByte(bits , 2);
??
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 9956
|
|
|
I wouldn't use a string at all. I'd use a byte, a bit mask, and bit-shift operations.
|
Never ascribe to malice that which can be adequately explained by stupidity.
|
 |
John Cobra
Greenhorn
Joined: Sep 06, 2011
Posts: 3
|
|
can you give a small example??
thanks
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 9956
|
|
I don't have time to put together formal code...beside, you'll learn more if you do it. but, in a nutshell, i'd do something like this:
|
 |
 |
|
|
subject: Help me with byte and bits
|
|
|