Last active
March 17, 2017 18:49
-
-
Save DBarthe/83ada33119ff52ab99773bf3f92d075e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Demonstration { | |
public void getIp(byte[] packet) { | |
// disons que l'ip commence à packet[0] | |
int w = packet[0] & 0xFF; // premier octet | |
int x = packet[1] & 0xFF; // deuxieme octet | |
int y = packet[2] & 0xFF; // troisieme... | |
int z = packet[3] & 0xFF; // quatrieme ... | |
// le '& 0xFF' c'est pour que la convertion byte -> int se fasse comme on l'attend | |
// Pas besoin de cast ducoup | |
int ip = z | (y << 8) | (x << 16) | (w << 24); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment