<br/>
在網(wǎng)絡(luò)編程中,出于節(jié)約帶寬或者編碼的需要,通常需要以原生方式處理long和int,而不是轉(zhuǎn)換為string。
public class ByteOrderUtils {
public static byte[] int2byte(int res) { <br/>byte[] targets = new byte[4]; <br/><br/>targets[3] = (byte) (res & 0xff);// 最低位 <br/>targets[2] = (byte) ((res >> 8) & 0xff);// 次低位 <br/>targets[1] = (byte) ((res >> 16) & 0xff);// 次高位 <br/>targets[0] = (byte) (res >>> 24);// 最高位,無符號(hào)右移。 <br/>return targets; <br/>}
public static int byteArrayToInt(byte[] b){ <br/>byte[] a = new byte[4]; <br/>int i = a.length - 1,j = b.length - 1; <br/>for (; i >= 0 ; i--,j--) {//從b的尾部(即int值的低位)開始copy數(shù)據(jù) <br/>if(j >= 0) <br/>a[i] = b[j]; <br/>else <br/>a[i] = 0;//如果b.length不足4,則將高位補(bǔ)0 <br/>} <br/>int v0 = (a[0] & 0xff) << 24;//&0xff將byte值無差異轉(zhuǎn)成int,避免Java自動(dòng)類型提升后,會(huì)保留高位的符號(hào)位 <br/>int v1 = (a[1] & 0xff) << 16; <br/>int v2 = (a[2] & 0xff) << 8; <br/>int v3 = (a[3] & 0xff) ; <br/>return v0 + v1 + v2 + v3; <br/>}<br/><br/>public static byte[] long2byte(long res) { <br/>byte[] buffer = new byte[8]; <br/>for (int i = 0; i < 8; i++) { <br/>int offset = 64 - (i + 1) * 8; <br/>buffer[i] = (byte) ((res >> offset) & 0xff); <br/>}<br/>return buffer;<br/>}
public static long byteArrayToLong(byte[] b){ <br/>long values = 0; <br/>for (int i = 0; i < 8; i++) { <br/>values <<= 8; values|= (b[i] & 0xff); <br/>} <br/>return values; <br/>}
}
<br/>

Outils d'IA chauds

Undress AI Tool
Images de déshabillage gratuites

Undresser.AI Undress
Application basée sur l'IA pour créer des photos de nu réalistes

AI Clothes Remover
Outil d'IA en ligne pour supprimer les vêtements des photos.

Clothoff.io
Dissolvant de vêtements AI

Video Face Swap
échangez les visages dans n'importe quelle vidéo sans effort grace à notre outil d'échange de visage AI entièrement gratuit?!

Article chaud

Outils chauds

Bloc-notes++7.3.1
éditeur de code facile à utiliser et gratuit

SublimeText3 version chinoise
Version chinoise, très simple à utiliser

Envoyer Studio 13.0.1
Puissant environnement de développement intégré PHP

Dreamweaver CS6
Outils de développement Web visuel

SublimeText3 version Mac
Logiciel d'édition de code au niveau de Dieu (SublimeText3)