 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
giulio petrucci Guest
|
Posted: Fri Feb 27, 2004 7:58 pm Post subject: passare da un int ad una sequenza di bytes... |
|
|
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
|
Posted: Fri Feb 27, 2004 11:30 pm Post subject: Re: passare da un int ad una sequenza di bytes... |
|
|
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 |
|
 |
|
|
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
|
|