Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help me with byte and bits

 
John Cobra
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If i have string like

string bits = "00010010";

this will work?

byte bits = Byte.parseByte(bits , 2);

??
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12097
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wouldn't use a string at all. I'd use a byte, a bit mask, and bit-shift operations.
 
John Cobra
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you give a small example??

thanks
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12097
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:





 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic