I wonder does anybody know where i can get a class for manipulating binary numbers? I'd write it myself, but my assignment is due in 6 days & i don't really have time! Plus, it would break the rule about not reinventing the wheel. And i'm a very good girl  i don't want to break rules!!!
Thanks a mill,
Celine
We've heard that a million monkeys at a million keyboards would eventually reproduce the entire works of Shakespeare. Now, thanks to the Internet, we know this is not true.<br /> Robert Wilensky
I'd write it myself, but my assignment is due in 6 days & i don't really have time!
With this attitude, you won't find much help around here. A lot of people at the Ranch are very interested in helping you learn Java, but purty much nobody cares about your grades.
So what do you mean by "manipulating binary numbers?" What is your assignment exactly?
Erm, right. Sorry.
Well, what i'm doing is an applet which displays a Panel of 8 LED's. The user will be able to enter a word. Each char of the word will have to be converted to binary for display on the LED. If the bit is a one the bar is OFF if it is zero, the bar is ON:

 

 

top horizontal = Bit zero
top right vert = bit one
bottom right vert = bit two
bottom horiz = bit three
bot left vert = bit four
top right ver = bit five
middle horiz = bit six
Dot (not needed) = bit seven
So, i need a little class that will deal with the binary numbers. It might be handier if i did it with an array[8] of ints. What would you think?
Celine
We've heard that a million monkeys at a million keyboards would eventually reproduce the entire works of Shakespeare. Now, thanks to the Internet, we know this is not true.<br /> Robert Wilensky
What you need to do is called bit masking. If you use the binary AND operator ( & ) you can determine if a bit is set in your number. For example, if you wanted to see if the bottom left vertical element was turned on, you would do the following:
The binary AND operator works by comparing each bit in the number with each bit in the mask correspondingly. Wherever the mask has a zero, the result will have a zero in that position regardless of the value in the number. Only if the number has a 1 and the mask has a 1 will the result have a one in that position. Therefore only if the number has the same bit set as the mask will the result of the AND be greater than 0.
I think your bigger problem will be choosing a data structure to hold the alphabet encoding into lit segments. I suggest using a Hashtable to map each character you want to encode, to its encoding. you should then be able to us the following to retrieve the encoding:
Where ch is the current character you are matching in the user input.
Once you get some code together and are still having problems, post what you have and we'll be happy to give you some more help.
[ November 26, 2003: Message edited by: Tom Blough ]
Tom Blough<br /> <blockquote><font size="1" face="Verdana, Arial">quote:</font><hr>Cum catapultae proscriptae erunt tum soli proscripti catapultas habebunt.<hr></blockquote>
Wow, this is really helpful. Thank you very much. I'll go and try that now...
I'm not sure about hashtables as i've never used them before, but i'll try it out & if i run into any probs, i'll post again.
Thanks a million,
Celine
We've heard that a million monkeys at a million keyboards would eventually reproduce the entire works of Shakespeare. Now, thanks to the Internet, we know this is not true.<br /> Robert Wilensky