▼
Posts: 110
Threads: 24
Joined: Jan 1970
Hi everybody,
Just a question for all those amazingly knowledgeable
HP-programming experts in this Forum. I've recently got
a brand-new HP-16C, manuals and all, and have tried to
program a very simple calculation, for test purposes but
mostly for fun.
The problem is, I know next to nothing about this
particular machine, which has a very different function
set from, say, an HP-11C or 15C, and though what I'm
trying to do seems pretty simple, I can't figure out how
to do it nor can make any sense of reading the manuals.
The question is: I'm trying to perform a pure floating
point calculation (not octal, hexadecimal, binary or
whatever, just plain floating point), but there's a time
when I need just the INTeger part of a floating point
value. In an HP-11C or 15C or almost any other model, I
would simply use the built-in INT function, but either
I'm too dumb to notice, or there seems to be no INT function
on the 16C !
Now, I'm sure there must be some easy way of doing
just that, getting the INTeger part of a floating point
value, and then go on performing more floating point
computations with that value and the rest of the 4-level
floating point stack unaffected.
Can it be done ? How ? I just can't believe
it can't, and I'd rather blame myself for failing to see
the probably ultra-obvious correct procedure.
Any help would be greatly appreciated, many
thanks in advance, and excuse me if my question is
way too silly.
▼
Posts: 4,027
Threads: 172
Joined: Aug 2005
Hi;
you're no dumb at all. There is no INT function available in the 16C's Floating Point repertoire. If you have the Owner's Handbook, get Section 5. All available Floating Point resources are described there.
And now you teased me. I'll work on this subject soon, but I want you to check for this:
- go to Floating Point and store a number (say, 234.4567) in R0 ([STO] 0)
- clear X-register and go back to integer hexadecimal ([HEX])
- recall R0 and inspect its contents
you'll see the two rightmost digits are the exponent of ten, and the leftmost digits are the mantissa. As you are in HEX mode, you see that the numbers are stored in BCD coding, and you should "mask" the n leftmost digits, being n the exponent of ten (in our case, 2), remove the rest of the mantissa and save the so called "INT" representation back to R0. I believe it will need about 10-15 program steps. If you wanna try, tell me. I'll try this weekend.
Success.
Posts: 4,027
Threads: 172
Joined: Aug 2005
Hi;
I read your post again and you mention a bradn-new HP16C; my first question is: where did you get this?
You also mention "manuals" two times in your post. The second question is: which is the other namual than the Owner's Handbook?
Thanks. (any success already?)
Posts: 172
Threads: 21
Joined: Sep 2005
Try this (it works for positive floating point numbers in X-register):
EEX; 9; +; LAST X; -
It can also replace RND function if you replace 9 by 9-N, where N is the number of digits after the decimal point you want to preserve.
I have used this a lot on my HP33E when I was in high school (more than 20 years ago).
Nenad
▼
Posts: 540
Threads: 22
Joined: Jan 2005
Neat, but there's no EEX on a 16. <g> It really *is* a very different beast.
Best,
--- Les Bell, CISSP
[http://www.lesbell.com.au]
▼
Posts: 540
Threads: 22
Joined: Jan 2005
Bzzzt! Earth to Les: Of *course* there's an EEX button on the 16, it's just f-CHS, where you can't see it in a dark office. . . .
Sorry, Nenad - your technique will work just fine.
Best,
--- Les Bell, CISSP
[http://www.lesbell.com.au]
Posts: 4,027
Threads: 172
Joined: Aug 2005
HI, Nenad;
What to say? Simple procedure, brilliant solution.
Cheers.
▼
Posts: 110
Threads: 24
Joined: Jan 1970
Thanks to both of you for your imaginative solutions.
Adding a large number will certainly work, though I will
have to take into account the sign of the numbers, as
they can be negative at that stage and if so I would need
to subtract instead of adding.
I was thinking that perhaps there was some way of changing
to some integer mode, do some operation with the number,
then return to floating point with the truncated result,
but could find no way to do it.
As for Luiz's question, I got the machine while visiting
a new acquaintance to whom I told casually I was interested in HP calcs. Much to my astonishment, she then produced the still boxed machine from a drawer where it had been
stored for the last 20 years or so. Everything was unused,
brand-new, even the Owner's Handbook was still shrink-wrapped. Not wishing to open it up, I got a copy of
a book from the "Easy Course ..." series, but couldn't
find any reference to an INT function anywhere. That
particular book is large, heavy, and makes fun reading,
but probably is no substitute for the manual proper.
Again, thanks to both of you, you've been most helpful.
▼
Posts: 4,027
Threads: 172
Joined: Aug 2005
Hi;
If you need to keep your original manual as it is, let me know. I'll scan the original (I have one) and send you the images.
If I have one HP16C Owner's Manual packed, I'd do what is needed to keep it this way.
Cheers. (lucky guy...)
Posts: 44
Threads: 0
Joined: Jan 1970
I'm afraid that's RND, not INT.
For INT, do:
.5 - EEX 9 + LASTX -
And even then, it does not always yield the correct answer due to 'unbiased rounding':
1. 'INT' -> 0.
2. 'INT' -> 1.
But I don't have a HP on which to test that. My 42S has unbiased rounding.
Werner Huysegoms
▼
Posts: 172
Threads: 21
Joined: Sep 2005
You are right, Werner, thank you. I have to improve it. If you need an INT (not a RND) you may use the following program (17 steps):
*LBLA; ENTER; ENTER; EEX; 9; +; LASTx; -; x>y; 1; 0; ENTER; 1; 0; /(divide); -; RTN
This was tested on HP11C and works for positive numbers. The program contains only the functions available on a HP16C (as seen from it's photo, not a real one:)
|