Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 93495 invoked from network); 21 Jun 2007 06:57:53 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 21 Jun 2007 06:57:53 -0000 Received: (qmail 91310 invoked by uid 500); 21 Jun 2007 06:57:51 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 90917 invoked by uid 500); 21 Jun 2007 06:57:50 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 90892 invoked by uid 99); 21 Jun 2007 06:57:50 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Jun 2007 23:57:50 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO brutus.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Jun 2007 23:57:46 -0700 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 3D4717141AA for ; Wed, 20 Jun 2007 23:57:26 -0700 (PDT) Message-ID: <1098895.1182409046248.JavaMail.jira@brutus> Date: Wed, 20 Jun 2007 23:57:26 -0700 (PDT) From: "Lilianne E. Blaze (JIRA)" To: commons-dev@jakarta.apache.org Subject: [jira] Created: (LANG-341) [NumberUtils] Please add number <> byte[] methods MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org [NumberUtils] Please add number <> byte[] methods ------------------------------------------------- Key: LANG-341 URL: https://issues.apache.org/jira/browse/LANG-341 Project: Commons Lang Issue Type: New Feature Reporter: Lilianne E. Blaze Hello, I need a set of methods to convert Long to or from a byte[] array, as if writing / reading from Data(Input/Output)Stream( ByteArray(Input/Output)Stream ). First, doing it with Streams seems a bit wasteful, second, it seems a pretty general use. Would it be possible to add something like that to, for example, org.apache.commons.lang.math.NumberUtils? Example code: static public long toLong(byte[] b) { return toLong(b, 0); } static public long toLong(byte[] b, int offset) { return (((long)b[offset] << 56) + ((long)(b[offset + 1] & 255) << 48) + ((long)(b[offset + 2] & 255) << 40) + ((long)(b[offset + 3] & 255) << 32) + ((long)(b[offset + 4] & 255) << 24) + ((b[offset + 5] & 255) << 16) + ((b[offset + 6] & 255) << 8) + ((b[offset + 7] & 255) << 0)); } static public byte[] longToByteArray(long l) { byte b[] = new byte[8]; longToByteArray(l, b, 0); return b; } static public void longToByteArray(long l, byte b[], int offset) { b[offset] = (byte)(l >>> 56); b[offset + 1] = (byte)(l >>> 48); b[offset + 2] = (byte)(l >>> 40); b[offset + 3] = (byte)(l >>> 32); b[offset + 4] = (byte)(l >>> 24); b[offset + 5] = (byte)(l >>> 16); b[offset + 6] = (byte)(l >>> 8); b[offset + 7] = (byte)(l >>> 0); } -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online. --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org