|
On Tue, 17 Sep 2002, Hopkins, Bill wrote: > > It's the fact that 4B is NOT equivalent to BINARY(4) that catches most folks > when they're first doing this. Maybe Jon can shed a little light on that > particular mystery. > It shouldn't take an expert like Jon to explain why BINARY(4) is different from 4B... it has, after all, been discussed here *MANY* times before. Remember this: 1) The API manual is not intended to be specifically for RPG programmers. It is intended for anyone writing software in any language on the iSeries. 2) Every different language has a different way of referring to a 32-bit binary integer. In C, it's called "int", but on some other platforms (such as MS-DOS or 16-bit Windows), an int might be only 16 bits. In CL, you'd use a CHAR(4) but put %bin() around it. In RPG IV, its correctly defined as 10I. In RPG III you had to define it in a data structure, by putting a "B" in column 43, and using from & to locations of 1-4 or 5-8, etc, etc, etc 3) So, to try to make the meaning clear, the API manual refers to the number of bytes long the variable needs to be. 4 bytes is 32 bits. That should be very clear. Now you just have to be familiar with your programming language to know how to define it. 4) In RPG, numeric variables (with the exception of floating point which was added later) are not defined by the number of bytes that they take up, but rather are defined by the number of DIGITS that they can hold. i.e. a "13P 3" is a 13 digit packed variable, it is only 7 bytes long. Likewise, a "4B 0" variable can hold up to 4 digits, but is only 2 bytes. Then, to add to the confusion, there's the differrence between the "9B 0" and "10I 0" data types. You see, a 32-bit binary integer can store values from -2147483648 to 2147483647. Even though those many seem like completely random numbers in decimal, in binary they are nice neat numbers, the highest values possible in 32 binary digits. But the nasty "9B 0" pseudo-binary number only stores values from -999999999 to 999999999, even tho they are considered "binary" they get cut off on a decimal digit boundary. The APIs aren't expecting this. Thats why I always tell people to use "10I 0" instead of "9B 0". It correctly uses all possible values of a 32-bit integer. What they should do is remove the "B" from the RPG manual, and have a compiler message that says "The B data type is deprecated, please replace it with a I" just like they do in every other language on every other platform. I know, I know, you can use decimal places with a "B" data type and not with an "I", and people think that this means "B" should stay. But, really, who uses that?!
As an Amazon Associate we earn from qualifying purchases.
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.