Paul Sheridan wrote:
>
> Greetings all,
> I need an answer to this ASAP so any help you could offer, or resource you could
>direct me too would be great ! this question may be slighty off-topic, but
>nonetheless I will be indebted for any help you could offer !
Hello Paul,
It would be nice if you could insert some carriage returns in
you paragraph sentences, otherwise those of us using Netscape
have a one mile long horizontal scrollbar.. ;-)
Paul Sheridan wrote:
> how do I change from decimal to base 16 and assign the value to a byte ?
>specifically for getting the base 16 value of the return of java.lang.String.length()
>
> e.g. if I have
>
> String myString = "ABCDEF..Z";
>
> then length() will return 26
> but what I want essentially what I need is:
>
> byte = SomeFunction(myString.length());
>
> where byte will have the value 0x19 in this case... so, what is the SomeFunction I
>apply to the return of String.length that will give me a hex assignment to the byte ?
>
Well, I have to say that I don't really understand your question..
A byte is a byte, independently of its look when you "print" it.
In fact, in the machine, everything is represented in *base 2*, but
for us human, most languages provide convenient methods to print
those values in base 10 or 8, or 16.
If I take your example and cut-n-paste it into the BSH (BeanShell,
a Java interpreter -w/o any compilation- that can be found at
http://www.beanshell.org/, a fantastic tool for testing), it gives:
| $ bsh
| BeanShell 1.0 beta - by Pat Niemeyer ([EMAIL PROTECTED])
| bsh % s = new String("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
| bsh % len = new Integer(s.length());
| bsh % print("\"" + s + "\" length is " + len);
| "ABCDEFGHIJKLMNOPQRSTUVWXYZ" length is 26
Ok, now we can see that this length, an integer value, can
be printed either in decimal or in hexadecimal. It does not
affect the way it is represented in machine, which is always
base 2 anyway! See below:
| bsh % String declenstring = Integer.toString(s.length());
| bsh % print(declenstring);
| 26
| bsh % String hexlenstring = Integer.toHexString(s.length());
| bsh % print(hexlenstring);
| 1a
It also works for byte values: if we parse one of these
representations and create a Byte object (because a simple
type like "byte" does not have any methods to work with, so
we are using a Byte object that encapsulates the value), then
we can still print this byte value either in decimal (base 10)
or in hexadecimal (base 16, and its "1A", not "19" :-), and this
does not affect at all the bits (base 2) that are stored in
the byte variable. See below:
| bsh % byte b = Byte.parseByte(declenstring);
| bsh % byteobj = new Byte(b);
| bsh % print(byteobj.toString());
| 26
| bsh % print(Integer.toHexString((int)byteobj.byteValue()));
| 1a
So I think you can safely send your byte value, or if you
need to have an hexadecimal string (for whatever reason),
then you can also compute it (and also "uppercase it" if needed).
Hope it helps.
Cheers,
Christophe.
= Bloody typical, they've gone back to metric without telling us. =
= -- Charlie, Department of Works (Brazil) =
--
-------------------------------------------------------------
[EMAIL PROTECTED] - Gemplus Research Lab
Phone: +33 4-42-36-57-83 | Disclaimer: I don't speak for Gemplus
Gemplus doesn't speak for me... it is better that way!
-------------------------------------------------------------
---
> Visit the OpenCard web site at http://www.opencard.org/ for more
> information on OpenCard---binaries, source code, documents.
> This list is being archived at http://www.opencard.org/archive/opencard/
! To unsubscribe from the [EMAIL PROTECTED] mailing list send an email
! to
! [EMAIL PROTECTED]
! containing the word
! unsubscribe
! in the body.