- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a large number (say 1000) of on/off bits of data which I want to represent as a set of integers (in this case 250 4 byte integers). I'm not sure how to do this as I don't think there is a bit datatype (1-bit). Logical*1 is 1 byte (8 bits). I'd like to do something like:
logical*1 :: lbig(1000)
integer*4 :: ibig(250)
equivalence(ibig(1), lbig(1))
but that doesn't work as the logical datatype is too big.
logical*1 :: lbig(1000)
integer*4 :: ibig(250)
equivalence(ibig(1), lbig(1))
but that doesn't work as the logical datatype is too big.
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Look at using BIT, BIC and BIS
integer*4 :: ibig(250)
...
ibig = 0
logical function yourTest(yourArray, yourBit)
integer*4 :: yourArray(250)
integer*4 :: yourBit
yourTest = (BIT(yourArray(yourBit / 32), MOD(yourBit, 32)) .ne. 0)
end function yourTest
The yourSet and yourClear will be variations on the above
You can also use C/C++ bit array funcitons
Jim Dempsey
integer*4 :: ibig(250)
...
ibig = 0
logical function yourTest(yourArray, yourBit)
integer*4 :: yourArray(250)
integer*4 :: yourBit
yourTest = (BIT(yourArray(yourBit / 32), MOD(yourBit, 32)) .ne. 0)
end function yourTest
The yourSet and yourClear will be variations on the above
You can also use C/C++ bit array funcitons
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If I understand it correctly, you want 1000 1/0 values, obtained from 1000 1 byte logicals, use to set the 4 bytes of 250 integers? If so, why don't use the TRANSFER statement
ibig = TRANSFER(lbig, ibig)
This works also fine in case you prefer to have the integer array being one with 1000 elements each 8 bits long!
Robert
ibig = TRANSFER(lbig, ibig)
This works also fine in case you prefer to have the integer array being one with 1000 elements each 8 bits long!
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Jim,
This is what I need- (not sure how the TRANSFER function is supposed to work)
This is what I need- (not sure how the TRANSFER function is supposed to work)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This example shows how to store and test 8000 bits. To store and test 1000 bits you need only 32 Integers so declaring ibig as integer*4::ibig(32) is sufficent.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting rwg
This example shows how to store and test 8000 bits. To store and test 1000 bits you need only 32 Integers so declaring ibig as integer*4::ibig(32) is sufficent.
This is correct, the code example provided was more or less a sketch of how to use a bit table.
The programmer can take this as a starting point. There are additional issues to consider for any complete implementation.
1) does the design require static allocation or dynamic allocation
2) should the bit field chunk be INTEGER*4 or INTEGER (KIND=INT_PTR_KIND())
3) Is the bit field used by a single thread or multiple threads
Issue 3, when used by multiple threads, will require atomic operations. However, by reconsidering to use 1 bit in single byte, you can then avoid an atomic operation and simply write the 0/1 into the byte.
Jim Dempsey
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