Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #1583
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail |
|---|---|
| From | Lew <lewbloch@gmail.com> |
| Newsgroups | comp.lang.java.help |
| Subject | Re: Help with BCD conversion |
| Date | Sat, 18 Feb 2012 10:25:51 -0800 (PST) |
| Organization | http://groups.google.com |
| Lines | 51 |
| Message-ID | <31483437.61.1329589551120.JavaMail.geo-discussion-forums@pbcr5> (permalink) |
| References | <92b642e7-0aa8-4e1a-9e4e-9418bfcc8123@k40g2000yqf.googlegroups.com> <8motj7ljbcapmd0i3kho2g7een4egail5m@4ax.com> <dfa613af-0f14-4d65-b12c-a6a119138e26@x19g2000yqh.googlegroups.com> <jhojbr$mql$1@dont-email.me> <5dlvj79ek56vcmqthh0cudaub6hhc78tsn@4ax.com> |
| NNTP-Posting-Host | 173.164.137.214 |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| X-Trace | posting.google.com 1329589656 10756 127.0.0.1 (18 Feb 2012 18:27:36 GMT) |
| X-Complaints-To | groups-abuse@google.com |
| NNTP-Posting-Date | Sat, 18 Feb 2012 18:27:36 +0000 (UTC) |
| In-Reply-To | <5dlvj79ek56vcmqthh0cudaub6hhc78tsn@4ax.com> |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=173.164.137.214; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T |
| User-Agent | G2/1.0 |
| X-Google-Web-Client | true |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.java.help:1583 |
Show key headers only | View raw
Roedy Green wrote: > The original IBM 360 style packed two decimal digits per nibble into > an 8 bit byte. It was stored big-endian. The last nibble encoded the That's BCD packed. There's also BCD unpacked. > sign, using one of the hex digits A-F. A, C, E, and F indicate > positive values, and B and D indicate negative values. Seems to me C, > D and F were preferred. > > IIRC there was no explicit length encoding. That was either > determined in the instruction code or by banging into the sign nibble. There's no explicit length encoding in Java's 'BigDecimal' either. There's no reason to expect one. > If there were an even number of digits, it was padded out with a left > zero. > > OP wants to simulate this on Java without the sign. It could be done > with a String, left zero padded to an even number of digits, which is > a trivial problem. It could be done with a byte array, two digits per > byte. The end result could be an int or long. You could start with a > String, int or long. I wanted OP to be aware of the possible choices > and pick the best for his purposes before nailing down code. > > This nibble packing is very similar to converting a Hex string to an > int. > > The core packing code is something like this > int lowNibble = ... > int highNibble = ... > int combinedbyte = highNibble << 8 | lowNibble; > > You probably don't want to use the byte type because it sign extends. > I have yet to find a need for signed bytes. I wish Java had made > bytes unsigned. It would have saved so many hair follicles. That's not a reason not to use the byte type. You just have to compensate for it. Don't throw the baby out with the bath water. > The code OP presented with case clauses is fundamentally incorrect in > that it treats each of the cases as different. They are not, and > should be handled by the same code.I think that is mainly why everyone > has been reluctant to delve into it. Amen to that. -- Lew
Back to comp.lang.java.help | Previous | Next — Previous in thread | Next in thread | Find similar
Help with BCD conversion HarishD <harishdeshpande@gmail.com> - 2012-02-17 15:21 -0800
Re: Help with BCD conversion Roedy Green <see_website@mindprod.com.invalid> - 2012-02-17 15:33 -0800
Re: Help with BCD conversion HarishD <harishdeshpande@gmail.com> - 2012-02-17 15:39 -0800
Re: Help with BCD conversion HarishD <harishdeshpande@gmail.com> - 2012-02-17 15:47 -0800
Re: Help with BCD conversion markspace <-@.> - 2012-02-18 08:24 -0800
Re: Help with BCD conversion Roedy Green <see_website@mindprod.com.invalid> - 2012-02-18 09:06 -0800
Re: Help with BCD conversion Lew <lewbloch@gmail.com> - 2012-02-18 10:25 -0800
Re: Help with BCD conversion HarishD <harishdeshpande@gmail.com> - 2012-02-20 06:35 -0800
Re: Help with BCD conversion Lew <noone@lewscanon.com> - 2012-02-20 11:52 -0800
Re: Help with BCD conversion Lew <lewbloch@gmail.com> - 2012-02-18 10:21 -0800
csiph-web