- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Suppose I have an integer with one of the following status values:
Code:
INTEGER*4, PARAMETER :: BIT_01 = Z'00000001' INTEGER*4, PARAMETER :: BIT_02 = Z'00000002' INTEGER*4, PARAMETER :: BIT_03 = Z'00000004' INTEGER*4, PARAMETER :: BIT_04 = Z'00000008' INTEGER*4, PARAMETER :: BIT_05 = Z'00000010' INTEGER*4, PARAMETER :: BIT_06 = Z'00000020' INTEGER*4, PARAMETER :: BIT_07 = Z'00000040' INTEGER*4, PARAMETER :: BIT_08 = Z'00000080' INTEGER*4, PARAMETER :: BIT_09 = Z'00000100' INTEGER*4, PARAMETER :: BIT_10 = Z'00000200' INTEGER*4, PARAMETER :: BIT_11 = Z'00000400' INTEGER*4, PARAMETER :: BIT_12 = Z'00000800' INTEGER*4, PARAMETER :: BIT_13 = Z'00001000' INTEGER*4, PARAMETER :: BIT_14 = Z'00002000' INTEGER*4, PARAMETER :: BIT_15 = Z'00004000' INTEGER*4, PARAMETER :: BIT_16 = Z'00008000' INTEGER*4, PARAMETER :: BIT_17 = Z'00010000' INTEGER*4, PARAMETER :: BIT_18 = Z'00020000' INTEGER*4, PARAMETER :: BIT_19 = Z'00040000' INTEGER*4, PARAMETER :: BIT_20 = Z'00080000' INTEGER*4, PARAMETER :: BIT_21 = Z'00100000' INTEGER*4, PARAMETER :: BIT_22 = Z'00200000' INTEGER*4, PARAMETER :: BIT_23 = Z'00400000' INTEGER*4, PARAMETER :: BIT_24 = Z'00800000' INTEGER*4, PARAMETER :: BIT_25 = Z'01000000' INTEGER*4, PARAMETER :: BIT_26 = Z'02000000' INTEGER*4, PARAMETER :: BIT_27 = Z'04000000' INTEGER*4, PARAMETER :: BIT_28 = Z'08000000' INTEGER*4, PARAMETER :: BIT_29 = Z'10000000' INTEGER*4, PARAMETER :: BIT_30 = Z'20000000' INTEGER*4, PARAMETER :: BIT_31 = Z'40000000' INTEGER*4, PARAMETER :: BIT_32 = Z'80000000'
Bits 17-32 are serious errors, but I only want to know if any one of them has occurred.
What is the most efficient way of doing this?
At first I thought of:
Code:
IF (value .GE. BIT_17) THEN
but BIT_32 = -2147483648, so that won't work.
Should I bit shift 'value' and test it against a lower value?
Link Copied
8 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
bits = ISHA(BIT_32, -16)
'bits' is now equal to #FFFF8000 (-32768)
But ISHA documentation says:
"Bits shifted out from the left or from the right, as appropriate, are lost. Zeros are shifted in from the opposite end."
Eh?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What am I thinking.....?
Code:
IF (ABS(value) .GE. BIT_17) THEN
Ought to work, right?
Edit:
Nope.... integer overflow when value = BIT_32
Message Edited by judd on 08-02-2005 02:57 PM
Message Edited by judd on 08-02-2005 02:57 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
OK,
this works, but it a bit messy I think
Code:
bits = ISHA(value, -16) IF (bits .NE. 0) THEN
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You want to look at the intrinsics IBITS or BTEST. You could also use IAND with a mask.
ISHA is an arithmetic shift, so if you shift to the right, the sign bit is propagated. ISHFT is a logical shift which brings in zeroes.
ISHA is an arithmetic shift, so if you shift to the right, the sign bit is propagated. ISHFT is a logical shift which brings in zeroes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I saw BTEST and BIT, but didn't want to do IF BTEST.OR. BTEST . OR. BTEST etc...
IAND with a mask shounds like the best option.
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
if(AND(value, -BIT_17) .NE. 0) then
or
INTEGER*4, PARAMETER :: BITS_HARD_ERROR = Z'FFFF0000'
...
if(AND(value, BITS_HARD_ERROR) .NE. 0) then
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
IAND, not AND.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jim,
Yep, I arrived at something similar to your 'HARD_ERROR' approach...thanks though.
Dan
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page