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


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

Re: creating byte[] with subfields

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!us.feeder.erje.net!feeder.erje.net!eu.feeder.erje.net!news-1.dfn.de!news.dfn.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Nigel Wade <nmw@ion.le.ac.uk>
Newsgroups comp.lang.java.programmer
Subject Re: creating byte[] with subfields
Date Fri, 18 Jan 2013 16:23:35 +0000
Lines 15
Message-ID <altb87Fd6hbU1@mid.individual.net> (permalink)
References <o62if8p1orppd2poseimactf3rqu0s04kn@4ax.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Trace individual.net 0J7f2EzAWxTBTmeeCqLW4gfG3XIYAaN7ivC4bNbbjXcgGWKv11MAUP9QFDmU1rzxiI
Cancel-Lock sha1:oek9c4BzE3L9mp8W/eOdxTNmr78=
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120601 Thunderbird/13.0
In-Reply-To <o62if8p1orppd2poseimactf3rqu0s04kn@4ax.com>
Xref csiph.com comp.lang.java.programmer:21521

Show key headers only | View raw


On 18/01/13 08:35, Roedy Green wrote:
> I often have to construct byte arrays with binary fields, or read
> them.
>
> I use a ByteArrayOutputStream and a DataOutputStream to compose them.
> I wondered if there is a simpler way, one that does not require
> computing each byte individually with shifts.
>

BitSet, and its toByteArray() method may do what you require.

I've not tried it myself. I still do it by shift/mask.

-- 
Nigel Wade

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


Thread

creating byte[] with subfields Roedy Green <see_website@mindprod.com.invalid> - 2013-01-18 00:35 -0800
  Re: creating byte[] with subfields Jim Janney <jjanney@shell.xmission.com> - 2013-01-18 08:31 -0700
    Re: creating byte[] with subfields Jim Janney <jjanney@shell.xmission.com> - 2013-01-18 10:29 -0700
  Re: creating byte[] with subfields Nigel Wade <nmw@ion.le.ac.uk> - 2013-01-18 16:23 +0000
  Re: creating byte[] with subfields Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-01-18 10:53 -0800
    Re: creating byte[] with subfields Roedy Green <see_website@mindprod.com.invalid> - 2013-01-18 14:23 -0800
      Re: creating byte[] with subfields Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-01-18 15:16 -0800
        Re: creating byte[] with subfields Roedy Green <see_website@mindprod.com.invalid> - 2013-01-18 23:24 -0800
          Re: creating byte[] with subfields Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-01-19 21:46 -0800
            Re: creating byte[] with subfields Joshua Cranmer <Pidgeot18@verizon.invalid> - 2013-01-20 11:01 -0600
              Re: creating byte[] with subfields Arne Vajhøj <arne@vajhoej.dk> - 2013-01-20 12:54 -0500
            Re: creating byte[] with subfields Arne Vajhøj <arne@vajhoej.dk> - 2013-01-20 12:51 -0500
        Re: creating byte[] with subfields Arne Vajhøj <arne@vajhoej.dk> - 2013-01-19 13:34 -0500
  Re: creating byte[] with subfields Arne Vajhøj <arne@vajhoej.dk> - 2013-01-18 20:33 -0500
    Re: creating byte[] with subfields Arne Vajhøj <arne@vajhoej.dk> - 2013-01-18 20:48 -0500

csiph-web