Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > bit operations in Java

Reply
Thread Tools

bit operations in Java

 
 
Sanket Suryawanshi
Guest
Posts: n/a
 
      01-23-2004
Hi friends,
I am doing a simulation on Data link layer. for which I need to pass
bits on the channel which is a Integer array.
to pass data in 0's and 1's I need to convert the
variable(char,int,String) into binary string.

Are there any functions in Java to convert CharToBinary, IntToBinary
which returns String and converts the BinaryToInt and BinaryToChar
also

plz help
 
Reply With Quote
 
 
 
 
Joona I Palaste
Guest
Posts: n/a
 
      01-23-2004
Sanket Suryawanshi <(E-Mail Removed)> scribbled the following:
> Hi friends,
> I am doing a simulation on Data link layer. for which I need to pass
> bits on the channel which is a Integer array.
> to pass data in 0's and 1's I need to convert the
> variable(char,int,String) into binary string.


> Are there any functions in Java to convert CharToBinary, IntToBinary
> which returns String and converts the BinaryToInt and BinaryToChar
> also


What does a "binary string" mean? Do you mean a String object holding
the binary representation of an integer value, for example 0 becomes
"0", 1 becomes "1", 2 becomes "10", 3 becomes "11" and so on?

--
/-- Joona Palaste ((E-Mail Removed)) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"No, Maggie, not Aztec, Olmec! Ol-mec!"
- Lisa Simpson
 
Reply With Quote
 
 
 
 
Oscar Kind
Guest
Posts: n/a
 
      01-23-2004
Sanket Suryawanshi <(E-Mail Removed)> wrote:
> bits on the channel which is a Integer array.
> to pass data in 0's and 1's I need to convert the
> variable(char,int,String) into binary string.
>
> Are there any functions in Java to convert CharToBinary, IntToBinary
> which returns String and converts the BinaryToInt and BinaryToChar
> also


Remember that a binary string is a number with radix 2.

Next, determine what you want to convert: a number (not a String; a String
probably needs to be parsed into a number).

Then, note that any (integer) number can be represented as a long, and
look at the API for java.lang.Long:
String binary = Long.toString(number, 2);
long number = Long.parseLong(binary, 2);

(note: this works slightly different with java.math.BigInteger)

Now you only have to catch the esceptions and you're set.


Oscar

--
No trees were harmed in creating this message.
However, a large number of electrons were terribly inconvenienced.
 
Reply With Quote
 
Jon A. Cruz
Guest
Posts: n/a
 
      01-23-2004
Oscar Kind wrote:
> Sanket Suryawanshi <(E-Mail Removed)> wrote:
>
>>bits on the channel which is a Integer array.
>>to pass data in 0's and 1's I need to convert the
>>variable(char,int,String) into binary string.
>>
>>Are there any functions in Java to convert CharToBinary, IntToBinary
>>which returns String and converts the BinaryToInt and BinaryToChar
>>also

>
>
> Remember that a binary string is a number with radix 2.



*Unless*, that is, he's coming from the viewpoint of C/C++ programmers
who often shove things in the 'strings' that are actually just byte arrays.


 
Reply With Quote
 
 
 
Reply

Thread Tools

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 Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the point of having 16 bit colour if a computer monitor can only display 8 bit colour? How do you edit 16 bit colour when you can only see 8 bit? Scotius Digital Photography 6 07-13-2010 03:33 AM
"LoadLibrary" of a 32 bit so with 64 bit java on a 64 bit machine markryde@gmail.com Java 3 01-19-2007 10:30 PM
stand-alone JMS, other JDBC operations, and transactions ( ActiveMQ + JOTM + JDBC operations ) Jesus M. Salvo Jr. Java 2 02-11-2006 06:33 PM
64 bit - Windows Liberty 64bit, Windows Limited Edition 64 Bit, Microsoft SQL Server 2000 Developer Edition 64 Bit, IBM DB2 64 bit - new ! vvcd Computer Support 0 09-17-2004 08:15 PM
64 bit - Windows Liberty 64bit, Windows Limited Edition 64 Bit,Microsoft SQL Server 2000 Developer Edition 64 Bit, IBM DB2 64 bit - new! Ionizer Computer Support 1 01-01-2004 07:27 PM



Advertisments