× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



On Tue, 17 Sep 2002, Joe Pluta wrote:
>
> I didn't ask why the 4B and BINARY(4) were different, Scott.
>

Actually, I was replying to Bill who made referred to "binary(4) and 4B"
being different as a "mystery." and asked for Jon Paris to explain it.

> What I asked was why a 4B field is the same size as a 5I field, but not the
> same size as a 5B field, which is even more confusing than the 4B/BINARY(4)
> mismatch.  You've alluded to the fact that it has to do with decimal
> precision.  A 5I field can hold any decimal representation of a two-byte
> binary field, which can in turn hold any four-digit decimal number (4B).
>

A 16-bit (2 byte) binary integer can store values up to 32767.  (or, an
unsigned can go up to 65535)  That's 5 decimal digits, but higher values
(for example 99999) can not be stored in it.

Therefore, the "5B 0" data type, in order to handle any 5-digit decimal
number, actually allocates 4 bytes.   The same amount of space is used for
5B 0 as is used for 9B 0.

This is the same, in concept, to the way a packed number works when it
has an even number of digits.   "8P 0" reserves space in memory for
9 packed digits and a sign...  but only lets you use 8 digits.
And "5B 0" allocates space for 9 digits (or 10, depending on how you look
at it) but only lets you use 5 of them.

To summarize:
So, if you allocate 1-4 digits for a "B" variable, you get 2 bytes (16
bits), if you allocate 5-9 you get 4 bytes (32 bits).   Bits are binary
digits.  In 16 bits, you should be able to store values to 32767, but
RPG will only let you use values up to 9, 99, 999 or 9999 if you declare
your variable as 1,2,3, or 4 digits respectively.   Likewise, 32 bits
can store values up to 2147483647.   But, RPG will limit you to 5-9
decimal digits (99999 to 999999999) in the "B" data type.

The I and U data types are "true" binary fields in that RPG does not
limit you...  it allows you to use all bits to represent any number
that those bits can represent.   There's no added limitation based on
the number of decimal digits.





As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.