Java Byte Array Create toBytesInt32BE(int w)

Here you can find the source of toBytesInt32BE(int w)

Description

to Bytes Int BE

License

Open Source License

Declaration

public static byte[] toBytesInt32BE(int w) 

Method Source Code

//package com.java2s;

public class Main {
    public static byte[] toBytesInt32BE(int w) {
        byte[] ret = new byte[4];
        writeInt32BE(ret, 0, w);//from   w  ww  .ja v  a 2 s . c o  m
        return ret;
    }

    public static void writeInt32BE(byte[] target, int offset, int w) {
        target[offset] = (byte) ((w >> 24) & 0xFF); // most significant byte first
        target[offset + 1] = (byte) ((w >> 16) & 0xFF);
        target[offset + 2] = (byte) ((w >> 8) & 0xFF);
        target[offset + 3] = (byte) (w & 0xFF); // least significant byte next
    }
}

Related

  1. toBytesFromHexString(String digits)
  2. toBytesFromOct(String octSymbols)
  3. toBytesFromString(String s)
  4. toBytesFromUnicode(String s)
  5. toBytesHexEscaped(final byte[] s, final int off, final int len)
  6. toBytesLittleEndian(long value, int cnt)
  7. toBytesOctalEscaped(final byte[] s, final int off, final int len)
  8. toBytesShortBE(short w)
  9. toBytesString(byte[] bytes)