AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

passare da un int ad una sequenza di bytes...

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java (Italian)
View previous topic :: View next topic  
Author Message
giulio petrucci
Guest





PostPosted: Fri Feb 27, 2004 7:58 pm    Post subject: passare da un int ad una sequenza di bytes... Reply with quote



supponiamo che io abbia a che fare con un intero che esca dalla
portata del singolo byte (ossia maggiore di 127 o minore di -128).
come posso fare per trasformarlo nella corrispondente sequenza di
bytes?
grazie
--
"show me a sign to a life that shines
one direction into another sheltered peace of mind"
skid row
--

[email]gpetrux (AT) BLAHlibero (DOT) it[/email]
rimuovi BLAH per rispondermi

- God Bless -

Back to top
APB
Guest





PostPosted: Fri Feb 27, 2004 11:30 pm    Post subject: Re: passare da un int ad una sequenza di bytes... Reply with quote



Forse sarebbe più semplice risponderti se ci spiegassi cosa vuoi farne di
questa sequenza di byte.

Puoi fare diverse "maschere di bit" per isolare via via il primo byte, il
secondo, il terzo... (tipo numero && 0xFFFF00)

Oppure fare successivi shift a destra...

Questo è una porzione di codice che ho trovato (ma non provato)

static byte[] intToByteArray ( int value ) {
byte[] arr = new byte[4];
arr[0] = (byte ) (value);
arr[1] = (byte ) (value >> 8 );
arr[2] = (byte ) (value >> 16 );
arr[3] = (byte ) (value >> 24);
return(arr);

Alex.
--
___________________________________________________________
a p bertolini

(www.webwarrior.org)


Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java (Italian) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.