programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering OS Languages Paradigms IDEs Build Tools Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# binary conversion?

vijay umar
Ranch Hand
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
Posts: 774
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,

fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
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.

Tim McGuire
Ranch Hand
Posts: 820

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
Posts: 100
it will be really helpful if some one post the code

Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
vijay umar wrote:it will be really helpful if some one post the code

... code which does what?

vijay umar
Ranch Hand
Posts: 100
code to convert the alphabetic characters into binary form

Tim McGuire
Ranch Hand
Posts: 820
vijay umar wrote:code to convert the alphabetic characters into binary form

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
Posts: 21133
87

David Newton
Author
Rancher
Posts: 12617
vijay umar wrote:it will be really helpful if some one post the code

fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
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.

 Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters?