Quantcast

Java bit-wise operators

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Java bit-wise operators

George Hovey-2
I just discovered bit-wise operators have been in Java at least since java se7.  the specs are available here:

   http://docs.oracle.com/javase/specs/index.html

Could consideration please be given to supporting them in NetRexx?  At the moment I must code them in Java, which I do only falteringly.

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Java bit-wise operators

Kermit Kiser
Hi George!

If you are looking for bit-wise logical operations, they have always been in NetRexx as part of the binary arithmetic support.

In the past, they required a binary class or method to use but 3.04 NetRexx allows individual instructions or groups of instructions to operate in binary by enclosing them with "do binary" and "end".

Note that the exclusive or operator in NetRexx is "&&" rather than the caret used by Java.

Example:

Do binary
Int3 = int1 && int2
End

Hope this helps.
-Kermit

On April 25, 2016 4:28:56 AM PDT, George Hovey <[hidden email]> wrote:
I just discovered bit-wise operators have been in Java at least since java se7.  the specs are available here:

   http://docs.oracle.com/javase/specs/index.html

Could consideration please be given to supporting them in NetRexx?  At the moment I must code them in Java, which I do only falteringly.



Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/


--
Sent from my Android device with K-9 Mail.
_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Java bit-wise operators

George Hovey-2
Kermit,

Relieved to see you are still on the case!

Certainly helps to have fine control over the scope of 'binary'.  What seems missing is shifting:

   https://docs.oracle.com/javase/tutorial/java/nutsandbolts/op3.html

I have various workarounds for dealing with this, but partly for performance reasons I'd like to get much closer to native code.  I need to write things like this (though with comments!) in NetRexx:

if (invert_a)
value = (flipa[(value>>12)&0xF]<<12) | (flipa[(value>>8)&0xF]<<8) | (flipa[(value>>4)&0xF]<<4) |
(flipa[value&0xF]);
if (invert_b)
value = ((value & 0xF)<<12) | ((value>>4) & 0xF00) | ((value>>8) & 0xF0) | ((value>>12) & 0xF);

This is a fragment of code specified by a computer engineer.  I'd like my version to resemble his as closely as possible because the effects of a mistake might be quite difficult to detect, and we are pretty much reduced to hand checking my effort.




On Mon, Apr 25, 2016 at 1:32 PM, Kermit Kiser <[hidden email]> wrote:
Hi George!

If you are looking for bit-wise logical operations, they have always been in NetRexx as part of the binary arithmetic support.

In the past, they required a binary class or method to use but 3.04 NetRexx allows individual instructions or groups of instructions to operate in binary by enclosing them with "do binary" and "end".

Note that the exclusive or operator in NetRexx is "&&" rather than the caret used by Java.

Example:

Do binary
Int3 = int1 && int2
End

Hope this helps.
-Kermit

On April 25, 2016 4:28:56 AM PDT, George Hovey <[hidden email]> wrote:
I just discovered bit-wise operators have been in Java at least since java se7.  the specs are available here:

   http://docs.oracle.com/javase/specs/index.html

Could consideration please be given to supporting them in NetRexx?  At the moment I must code them in Java, which I do only falteringly.



Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/


--
Sent from my Android device with K-9 Mail.

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/





--
"Life isn't one damn thing after another -- it's the same damn thing over and over."
  -- Edna St Vincent Millay

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Java bit-wise operators

Kermit Kiser
I have also speculated on the missing shift operators but my suspicion is that Mike omitted them in the interest of keeping things minimal. They may not have been in Java originally either.

Bit shifting is equivalent to multiplying or dividing by powers of two so it should be easy to roll your own NetRexx operators:
*2**n for <<n
%2**n for >>n

Unfortunately I am currently trapped in a hospital with no computer so I can't verify this stuff. You should check it to see if it gives what you need, especially the bits shifting in or out the ends.

-Kermit

On April 25, 2016 1:53:54 PM PDT, George Hovey <[hidden email]> wrote:
Kermit,

Relieved to see you are still on the case!

Certainly helps to have fine control over the scope of 'binary'.  What seems missing is shifting:

   https://docs.oracle.com/javase/tutorial/java/nutsandbolts/op3.html

I have various workarounds for dealing with this, but partly for performance reasons I'd like to get much closer to native code.  I need to write things like this (though with comments!) in NetRexx:

if (invert_a)
value = (flipa[(value>>12)&0xF]<<12) | (flipa[(value>>8)&0xF]<<8) | (flipa[(value>>4)&0xF]<<4) |
(flipa[value&0xF]);
if (invert_b)
value = ((value & 0xF)<<12) | ((value>>4) & 0xF00) | ((value>>8) & 0xF0) | ((value>>12) & 0xF);

This is a fragment of code specified by a computer engineer.  I'd like my version to resemble his as closely as possible because the effects of a mistake might be quite difficult to detect, and we are pretty much reduced to hand checking my effort.




On Mon, Apr 25, 2016 at 1:32 PM, Kermit Kiser <[hidden email]> wrote:
Hi George!

If you are looking for bit-wise logical operations, they have always been in NetRexx as part of the binary arithmetic support.

In the past, they required a binary class or method to use but 3.04 NetRexx allows individual instructions or groups of instructions to operate in binary by enclosing them with "do binary" and "end".

Note that the exclusive or operator in NetRexx is "&&" rather than the caret used by Java.

Example:

Do binary
Int3 = int1 && int2
End

Hope this helps.
-Kermit

On April 25, 2016 4:28:56 AM PDT, George Hovey <[hidden email]> wrote:
I just discovered bit-wise operators have been in Java at least since java se7.  the specs are available here:

   http://docs.oracle.com/javase/specs/index.html

Could consideration please be given to supporting them in NetRexx?  At the moment I must code them in Java, which I do only falteringly.



Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/


--
Sent from my Android device with K-9 Mail.

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/





--
Sent from my Android device with K-9 Mail.
_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Java bit-wise operators

Mike Cowlishaw
I have also speculated on the missing shift operators but my suspicion is that Mike omitted them in the interest of keeping things minimal. They may not have been in Java originally either.  
 
I thought about this extensively.  NetRexx is natively decimal so it seemed messy to have operators that only worked in binary mode.  I did think of them doing digit-shifts on decimal numbers, but it really didn't feel right (the multiply/divide by powers of ten works there, anyway, if really needed). 

Bit shifting is equivalent to multiplying or dividing by powers of two so it should be easy to roll your own NetRexx operators:
*2**n for <<n
%2**n for >>n 
 
Indeed.  Another argument for a macro facility in NetRexx, perhaps.... 

Unfortunately I am currently trapped in a hospital with no computer so I can't verify this stuff. You should check it to see if it gives what you need, especially the bits shifting in or out the ends.  
 
Thanks for helping out in such circumstances!
 
Mike 

   
On April 25, 2016 1:53:54 PM PDT, George Hovey <[hidden email]> wrote:
Kermit,

Relieved to see you are still on the case!

Certainly helps to have fine control over the scope of 'binary'.  What seems missing is shifting:

   https://docs.oracle.com/javase/tutorial/java/nutsandbolts/op3.html

I have various workarounds for dealing with this, but partly for performance reasons I'd like to get much closer to native code.  I need to write things like this (though with comments!) in NetRexx:

if (invert_a)
value = (flipa[(value>>12)&0xF]<<12) | (flipa[(value>>8)&0xF]<<8) | (flipa[(value>>4)&0xF]<<4) |
(flipa[value&0xF]);
if (invert_b)
value = ((value & 0xF)<<12) | ((value>>4) & 0xF00) | ((value>>8) & 0xF0) | ((value>>12) & 0xF);

This is a fragment of code specified by a computer engineer.  I'd like my version to resemble his as closely as possible because the effects of a mistake might be quite difficult to detect, and we are pretty much reduced to hand checking my effort.




On Mon, Apr 25, 2016 at 1:32 PM, Kermit Kiser <[hidden email]> wrote:
Hi George!

If you are looking for bit-wise logical operations, they have always been in NetRexx as part of the binary arithmetic support.

In the past, they required a binary class or method to use but 3.04 NetRexx allows individual instructions or groups of instructions to operate in binary by enclosing them with "do binary" and "end".

Note that the exclusive or operator in NetRexx is "&&" rather than the caret used by Java.

Example:

Do binary
Int3 = int1 && int2
End

Hope this helps.
-Kermit

On April 25, 2016 4:28:56 AM PDT, George Hovey <[hidden email]> wrote:
I just discovered bit-wise operators have been in Java at least since java se7.  the specs are available here:

   http://docs.oracle.com/javase/specs/index.html

Could consideration please be given to supporting them in NetRexx?  At the moment I must code them in Java, which I do only falteringly.



Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/


--
Sent from my Android device with K-9 Mail.

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/





--
Sent from my Android device with K-9 Mail.

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Java bit-wise operators

ThSITC
In reply to this post by George Hovey-2
*Would anybody have an* +objection+ *against me to re-introduce* ...

*Rey*

-- The successor of NetRexx ;-) ;-) ;-)
??????????????????????????????????????????
Thomas.
####################################################

Am 25.04.2016 um 13:28 schrieb George Hovey:
I just discovered bit-wise operators have been in Java at least since java se7.  the specs are available here:

   http://docs.oracle.com/javase/specs/index.html

Could consideration please be given to supporting them in NetRexx?  At the moment I must code them in Java, which I do only falteringly.


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/



_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Loading...