• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

binary conversion?

 
vijay umar
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 12101
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it will be really helpful if some one post the code
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vijay umar wrote:it will be really helpful if some one post the code


... code which does what?
 
vijay umar
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
code to convert the alphabetic characters into binary form
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vijay umar wrote:can any one reply to this urgently needed please

Please EaseUp.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vijay umar wrote:it will be really helpful if some one post the code

Please see NotACodeMill.
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12101
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic