Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #32935

Re: number to byte[]

Path csiph.com!news.swapon.de!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!feeder.erje.net!1.eu.feeder.erje.net!goblin3!goblin.stu.neva.ru!news.netfront.net!not-for-mail
From Lothar Kimmeringer <news200709@kimmeringer.de>
Newsgroups comp.lang.java.programmer
Subject Re: number to byte[]
Date Sun, 25 Oct 2015 10:22:31 +0100
Organization Organization?! Only chaos here!
Lines 23
Message-ID <1gwaeg94z8z3f.dlg@kimmeringer.de> (permalink)
References <mvsv9r$ohb$1@ls237.t-com.hr>
Reply-To news@kimmeringer.de
NNTP-Posting-Host 93.133.138.154
Mime-Version 1.0
Content-Type text/plain; charset="us-ascii"
Content-Transfer-Encoding 7bit
X-Trace adenine.netfront.net 1445764952 53799 93.133.138.154 (25 Oct 2015 09:22:32 GMT)
X-Complaints-To news@netfront.net
NNTP-Posting-Date Sun, 25 Oct 2015 09:22:32 +0000 (UTC)
User-Agent 40tude_Dialog/2.0.15.1de
Xref csiph.com comp.lang.java.programmer:32935

Show key headers only | View raw


Askfor wrote:

> I am trying to get 4 byte[] representation of an integer, which might be 
> 32 bit long.
> 
> Obviously, I could AND with 255 and take byteValue(), then shift 8 times 
> to the right and repeat the process 3 times. Is there any more elegant way ?

You could use BigInteger.toByteArray but I think you should stick
with the ANDing (put it in a helper method), since the mentioned
returns a byte-array of variable size (with five elements for
values > 0x0fffffff).


Cheers, Lothar
-- 
Lothar Kimmeringer                E-Mail: spamfang@kimmeringer.de
               PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
                 questions!

--- news://freenews.netfront.net/ - complaints: news@netfront.net ---

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

number to byte[] Askfor <askfor@nowhere.net> - 2015-10-17 10:02 +0200
  Re: number to byte[] Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-10-17 08:03 -0400
    Re: number to byte[] Askfor <askfor@nowhere.net> - 2015-10-17 23:03 +0200
      Re: number to byte[] Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-10-17 17:45 -0400
        Re: number to byte[] Askfor <askfor@nowhere.net> - 2015-10-18 12:13 +0200
          Re: number to byte[] Askfor <askfor@nowhere.net> - 2015-10-18 12:44 +0200
            Re: number to byte[] Lew <lewbloch@gmail.com> - 2015-11-29 23:07 -0800
          Re: number to byte[] Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-10-18 08:40 -0400
      Re: number to byte[] Nigel Wade <nmw@ion.le.ac.uk> - 2015-10-19 10:43 +0100
        Re: number to byte[] Wayne <nospam@all.invalid> - 2015-10-20 00:45 -0400
        Re: number to byte[] Kevin McMurtrie <mcmurtrie@pixelmemory.us> - 2015-10-20 13:35 -0700
  Re: number to byte[] Lothar Kimmeringer <news200709@kimmeringer.de> - 2015-10-25 10:22 +0100

csiph-web