Here you can find the source of toAscii(int i, boolean reversed)
Parameter | Description |
---|---|
i | The integer to interpret |
reversed | True for big-endian, false for little-endian |
public static String toAscii(int i, boolean reversed)
//package com.java2s; /**/*from w ww.j av a 2 s . c o m*/ * Copyright (C) 2011 Darien Hager * * This code is part of the "HL2Parse" project, and is licensed under * a Creative Commons Attribution-ShareAlike 3.0 Unported License. For * either a summary of conditions or the full legal text, please visit: * * http://creativecommons.org/licenses/by-sa/3.0/ * * Permissions beyond the scope of this license may be available * at http://technofovea.com/ . */ public class Main { /** * Given an integer value, reinterpret it as a string stored in four bytes. * * This is useful for a few places where developers have chosen integer IDs * which map to a human-readable mnemonic value. * * @param i The integer to interpret * @param reversed True for big-endian, false for little-endian * @return A string representation of the integer */ public static String toAscii(int i, boolean reversed) { byte[] bytes = new byte[4]; if (!reversed) { bytes[0] = (byte) (i >> 24); bytes[1] = (byte) ((i << 8) >> 24); bytes[2] = (byte) ((i << 16) >> 24); bytes[3] = (byte) ((i << 24) >> 24); } else { bytes[3] = (byte) (i >> 24); bytes[2] = (byte) ((i << 8) >> 24); bytes[1] = (byte) ((i << 16) >> 24); bytes[0] = (byte) ((i << 24) >> 24); } return new String(bytes); } }