Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #32891
| Path | csiph.com!goblin2!goblin.stu.neva.ru!news-hub.siol.net!news1.t-com.hr!.POSTED!not-for-mail |
|---|---|
| From | Askfor <askfor@nowhere.net> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: number to byte[] |
| Date | Sat, 17 Oct 2015 23:03:56 +0200 |
| Organization | T-Com |
| Lines | 28 |
| Message-ID | <mvud46$eat$1@ls237.t-com.hr> (permalink) |
| References | <mvsv9r$ohb$1@ls237.t-com.hr> <mvtd9u$c4m$1@dont-email.me> |
| NNTP-Posting-Host | 93-141-14-15.adsl.net.t-com.hr |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | ls237.t-com.hr 1445115846 14685 93.141.14.15 (17 Oct 2015 21:04:06 GMT) |
| X-Complaints-To | abuse@t-com.hr |
| NNTP-Posting-Date | Sat, 17 Oct 2015 21:04:06 +0000 (UTC) |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 |
| In-Reply-To | <mvtd9u$c4m$1@dont-email.me> |
| Xref | csiph.com comp.lang.java.programmer:32891 |
Show key headers only | View raw
On 10/17/2015 02:03 PM, Eric Sosman wrote: > On 10/17/2015 4:02 AM, 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 ? > > I can't think of one, off-hand. > > But *why* do you want this four-byte array? Are you planning to > write it to some output destination? If so, perhaps you should use a > DataOutputStream (or other DataOutput implementation) and call its > writeInt() method. Or, perhaps you should use an IntBuffer. What > are you trying to do? > It is going to be a part of a data header, which needs to be of fixed length. Also it will contain a value of an offset which cabn't be longer than 32-bits. So, I don't care how big int actually is, as long as it is big enough to hold 32 bit unsigned value. I started with serialization, too, but I realized it won't work. Thanks.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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