aspose file tools
The moose likes Java in General and the fly likes binary conversion? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "binary conversion?" Watch "binary conversion?" New topic
Author

binary conversion?

vijay umar
Ranch Hand

Joined: Mar 24, 2009
Posts: 100
hi people,

how we can convert alphabets like a,b,c,d into binary form?can any one reply to this urgently needed please
Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 771
Hello vinay,

I suppose this question should be asked in Java Beginner forum, this is certification related.
Please use meaningful subject line as well.

Best Regards,


Prithvi/Beenish,
My Blog, Follow me on Twitter,Scjp Tips, When you score low in mocks, Generics,Scjp Notes, JavaStudyGroup
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 9955
    
    6

What exactly do you mean? do you want to come up with your own conversion? then you can do it however you want.

If you want to know how the character 'a' would be stored natively by java, i'd start by looking at a ASCII table.


Never ascribe to malice that which can be adequately explained by stupidity.
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 819

start with "a"

ascii decimal for "a" ?

97

how to convert decimal into binary?

0 = 00000000
1 = 00000001
2 = 00000010
.
.
.
7 = 00000111
8 = 00001000

keep finding closest power of 2
2 to the 6th is 64
+
2 to the 5 is 32

makes 96

plus 1 is
97

so in decimal that should be
01000000 = 64
+
00100000 = 32
+
00000001 = 1
_____
01100001 = 97 = a
vijay umar
Ranch Hand

Joined: Mar 24, 2009
Posts: 100
it will be really helpful if some one post the code
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24061
    
  13

vijay umar wrote:it will be really helpful if some one post the code


... code which does what?


[Jess in Action][AskingGoodQuestions]
vijay umar
Ranch Hand

Joined: Mar 24, 2009
Posts: 100
code to convert the alphabetic characters into binary form
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 819

vijay umar wrote:code to convert the alphabetic characters into binary form


we are here to help you code this.
you have a String.
convert your string to array of characters
convert each char to decimal form
do you know how to convert a,b,c,d....z into decimal form?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

vijay umar wrote:can any one reply to this urgently needed please

Please EaseUp.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

vijay umar wrote:it will be really helpful if some one post the code

Please see NotACodeMill.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 9955
    
    6

vijay umar wrote:code to convert the alphabetic characters into binary form

This doesn't make sense. In java, and in fact all computing languages and computers in general, everything is stored in binary. that's all they understand are 1's and 0's. so, what you see as an 'a' is really stored as a number, and that is stored as a binary number. It all happens automatically.

So tell us what you really want to do. do you want to save the number? do you want to print the number value? do you want to use the pre-defined ASCII values, or come up with your own?

The single most important part of writing code is understanding what you want to do, and spec it out.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: binary conversion?
 
Similar Threads
ServletResponse Printwriter object
Binary Data in XML
WA #1.....word association
Ascii to binary and binary to ascii
bin vs source software