Integer To Four Bytes : Integer « Date Type « Android

Home
Android
1.2D Graphics
2.Animation
3.Core Class
4.Database
5.Date Type
6.Development
7.File
8.Game
9.Hardware
10.Media
11.Network
12.Security
13.UI
14.User Event
Android » Date Type » Integer 
Integer To Four Bytes
  

/*
 * This file is part of JSTUN. 
 
 * Copyright (c) 2005 Thomas King <king@t-king.de> - All rights
 * reserved.
 
 * This software is licensed under either the GNU Public License (GPL),
 * or the Apache 2.0 license. Copies of both license agreements are
 * included in this distribution.
 */
class Main{

  
  public static final byte[] integerToFourBytes(int valuethrows UtilityException {
    byte[] result = new byte[4];
    if ((value > Math.pow(2,63)) || (value < 0)) {
      throw new UtilityException("Integer value " + value + " is larger than 2^63");
    }
        result[0(byte)((value >>> 240xFF);
    result[1(byte)((value >>> 160xFF);
    result[2(byte)((value >>> 80xFF);
        result[3(byte)(value & 0xFF);
    return result; 
  }
}

class UtilityException extends Exception {
  private static final long serialVersionUID = 3545800974716581680L;

  UtilityException(String mesg) {
    super(mesg);
  }

}

   
    
  
Related examples in the same category
1.Integer To One Byte
2.Integer To Two Bytes
3.One Byte To Integer
4.Two Bytes To Integer
5.List to int[]
6.Tests if an integer is power of two
7.Convert an integer value to its byte array representation
8.Convert a byte array integer (4 bytes) to its int value
9.Convert a byte array representing an unsigned integer (4bytes) to its long value
10.fahrenheit To Celsius, celsius To Fahrenheit
11.Padding Int value
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.