Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ascii to Decimal - Eating my Brain. Urgent please

Status
Not open for further replies.

sujitopics

Programmer
Oct 9, 2001
69
KR
Dear Friends
I am facing pblm while converting ascii to dec.
at present my program is supporting to this..

ascii dec

a 61

but, when i give "aa" it is still saying 61 as decimal.

how can i make my program to get this type of result

aa 6161
aaa 616161

is it possible.

please help me.
Thanks in advance

Yours
Rajesh
 
hi Rajesh

here is the code for u r requirement.
class ascii {
public static void main(String args[]) {
String In="aa";
byte[] b =In.getBytes();
System.out.print(In+" ");
for(int i=0;i<b.length;i++)
System.out.print(b);
}
}
 
Dear skumar

Thankyou VeryMuch.
Your code helped me a lot.

I used ur code for ascii to hex conversion.
I used like this.

But i got a small problem in this.
when i use &quot;aa&quot; as decimal...it is showing 6161. it is fine. but
when i use &quot;ab&quot; as decimal...it is still showing as 6161 instead of 6162,

Please help me.
Code is like this.

Thanks in advance


class ascii
{
final static String HEXDIGITS=&quot;0123456789ABCDEF&quot;;
public final static char[] hex(int value)
{
char [] hexbuffer = new char[2];
hexbuffer[0] = HEXDIGITS.charAt((value >> 4) & 0x0f);
hexbuffer[1] = HEXDIGITS.charAt(value & 0x0f);
return hexbuffer;
}
public static void main(String args[])
{
String In=&quot;bc&quot;;
byte[] aByteArr =In.getBytes();
System.out.print(In + &quot; &quot;);
for(int i=0;i<aByteArr.length;i++)
{
byte aByte = aByteArr[1];
char [] charHex = hex((int)aByte);
System.out.print(charHex);
}
}
}


Thankyou VeryMuch
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top