FormatTransfer


Bitmap类源文件 http://download.csdn.net/detail/ccjjxx001/5049365 用于数据转换的补充类 大部分源码来自于网上 自己只有小的修改
资源截图
代码片段和文件信息
/*
 * Copyright (C) 2013 United States Government as represented by the Administrator of the
 * National Aeronautics and Space Administration.
 * All Rights Reserved.
 */

package gov.nasa.worldwindx.examples;

/**
* ��ʽת��
* Java��һЩwindows���������c��c++��delphi��д������������ͨѶʱ����Ҫ������Ӧ��ת��
* �ߡ����ֽ�֮���ת��
* windows���ֽ���Ϊ���ֽڿ�ͷ
* linuxunix���ֽ���Ϊ���ֽڿ�ͷ
* java������ƽ̨�仯�����Ǹ��ֽڿ�ͷ
  */

public class FormatTransfer
{
/**
  * ��intתΪ���ֽ���ǰ�����ֽ��ں��byte����
  * @param n int
  * @return byte[]
  */
public static byte[] toLH(int n) {
  byte[] b = new byte[4];
  b[0] = (byte) (n & 0xff);
  b[1] = (byte) (n >> 8 & 0xff);
  b[2] = (byte) (n >> 16 & 0xff);
  b[3] = (byte) (n >> 24 & 0xff);
  return b;
}

/**
  * ��intתΪ���ֽ���ǰ�����ֽ��ں��byte����
  * @param n int
  * @return byte[]
  */
public static byte[] toHH(int n) {
  byte[] b = new byte[4];
  b[3] = (byte) (n & 0xff);
  b[2] = (byte) (n >> 8 & 0xff);
  b[1] = (byte) (n >> 16 & 0xff);
  b[0] = (byte) (n >> 24 & 0xff);
  return b;
}

/**
  * ��shortתΪ���ֽ���ǰ�����ֽ��ں��byte����
  * @param n short
  * @return byte[]
  */
public static byte[] toLH(short n) {
  byte[] b = new byte[2];
  b[0] = (byte) (n & 0xff);
  b[1] = (byte) (n >> 8 & 0xff);
  return b;
}

/**
  * ��shortתΪ���ֽ���ǰ�����ֽ��ں��byte����
  * @param n short
  * @return byte[]
  */
public static byte[] toHH(short n) {
  byte[] b = new byte[2];
  b[1] = (byte) (n & 0xff);
  b[0] = (byte) (n >> 8 & 0xff);
  return b;
}



/**
  * ����intתΪ���ֽ���ǰ�����ֽ��ں��byte����

public static byte[] toHH(int number) {
  int temp = number;
  byte[] b = new byte[4];
  for (int i = b.length - 1; i > -1; i--) {
    b = new Integer(temp & 0xff).byteValue();
    temp = temp >> 8;
  }
  return b;
}

public static byte[] IntToByteArray(int i) {
    byte[] abyte0 = new byte[4];
    abyte0[3] = (byte) (0xff & i);
    abyte0[2] = (byte) ((0xff00 & i) >> 8);
    abyte0[1] = (byte) ((0xff0000 & i) >> 16);
    abyte0[0] = (byte) ((0xff000000 & i) >> 24);
    return abyte0;
}


*/

/**
  * ��floatתΪ���ֽ���ǰ�����ֽ��ں��byte����
  */
public static byte[] toLH(float f) {
  return toLH(Float.floatToRawIntBits(f));
}

/**
  * ��floatתΪ���ֽ���ǰ�����ֽ��ں��byte����
  */
public static byte[] toHH(float f) {
  return toHH(Float.floatToRawIntBits(f));
}

/**
  * ��StringתΪbyte����
  */
public static byte[] stringToBytes(String s int length) {
  while (s.getBytes().length < length) {
    s += “ “;
  }
  return s.getBytes();
}


/**
  * ���ֽ�����ת��ΪString
  * @param b byte[]
  * @return String
  */
public static String bytesToString(byte[] b) {
  StringBuffer result = new StringBuffer(““);
  int length = b.length;
  for (int i=0; i    result.append((char)(b[i] & 0xff));
  }
  return result.toString();
}

/**
  * ���ַ�ת��Ϊbyte����
  * @param s String
  * @return byte[]
  */
public static byte[] stringToByte

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)