Hello
I apologize if this is a boneheaded question, but what is the best way to mask an integer's bits in Oberon-07?
As I understand it, one way is to convert the integer to a SET and multiply . This conversion, however, requires use of the SYSTEM module. I'm trying to avoid that.
Another way is to use LSL and ASR to isolate bits, but that seems wasteful.
Is there some other way I'm missing?
thanks in advance
john perry
Hello
I apologize if this is a boneheaded question, but what is the best way to mask an integer's bits in Oberon-07?
As I understand it, one way is to convert the integer to a SET and multiply . This conversion, however, requires use of the SYSTEM module. I'm trying to avoid that.
Another way is to use LSL and ASR to isolate bits, but that seems wasteful.
Is there some other way I'm missing?
thanks in advance
john perry
Do you have SYSTEM.VAL function in the version of Oberon you use?
Carlcatch it right before it does, and use MOD then. In addition, I’m packing 2 or more numbers into a machine word, so as to do this arithmetic in parallel, so using the greater-than operator is out of the question.
Thank you for pointing out that interesting thread to me.
To address your question:
Do you have SYSTEM.VAL function in the version of Oberon you use?
I do, but I was trying to avoid it because I’m under the impression that should be used only for low-level programming.
Essentially, I’m performing some modular addition and multiplication, and trying to avoid using MOD until I know the integer has grown to a certain size. I’m doing a *lot* of operations, so I know the integer will eventually overflow, but I want to
I had already implemented this with a mask in a couple of other languages (C, Nim). I was curious how Oberon would handle it, and as I set about doing this, it quickly became apparent that you can’t mask an integer using a SET without falling back onSYSTEM.VAL.
I settled on using LSL and ASR, because it turns out to be pretty simple in this case and doesn’t affect efficiency. But the general question remained.
regards
john perry
—
John Perry + Associate Professor + Department of Mathematics
University of Southern Mississippi
Absent-mindedness is not absence of mind; it’s presence of mind elsewhere. — G.K. Chesterton
Carl
Thank you for pointing out that interesting thread to me.
To address your question:
Do you have SYSTEM.VAL function in the version of Oberon you use?
I do, but I was trying to avoid it because I’m under the impression that should be used only for low-level programming.
Curious if your using either Astrobe's implementation of Oberon-07 or perhaps Saanlima's Oberon Workstation?
Do you have SYSTEM.VAL function in the version of Oberon you use?
I do, but I was trying to avoid it because I’m under the impression that should be used only for low-level programming.
If you are performing bit mask operations on integer values then the Oberon view is that you ARE doing 'low-level programming'. The presence of the SYSTEM qualifier is to highlight that whatever you are doing might not be portable.
However, now that the shift operations in Oberon-07 are no longer SYSTEM operations the distinction between these and other built-in functions has become inconsistent / blurred. For more discussion on this see:
http://lists.inf.ethz.ch/pipermail/oberon/2018/012506.html
Thank you, that was an interesting read. I wonder if LSL and ASR are considered non-SYSTEM because they can be used for multiplication and division by 2 (which is really what I'm doing).
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 293 |
Nodes: | 16 (2 / 14) |
Uptime: | 215:47:20 |
Calls: | 6,620 |
Calls today: | 2 |
Files: | 12,169 |
Messages: | 5,317,547 |