- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The question was posed to me by a programmer colleague and so I ask, "Is there a way/trick/tip in FORTRAN to define and declare a 1-bit integer?
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
No. There had been a proposal to add a "bit" type to the language, but it ran into a lot of opposition. The language does have a good set of routines for manipulating bits in integers (IBITS, IBSET, IBCLR, MVBITS, IAND, IOR, etc.)
Out of curiosity, what would you expect a 1-bit integer to do? In Fortran, all integers are signed, so there are no bits left for value. (There had also been proposals for unsigned integers which also failed.)
Out of curiosity, what would you expect a 1-bit integer to do? In Fortran, all integers are signed, so there are no bits left for value. (There had also been proposals for unsigned integers which also failed.)
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
No. There had been a proposal to add a "bit" type to the language, but it ran into a lot of opposition. The language does have a good set of routines for manipulating bits in integers (IBITS, IBSET, IBCLR, MVBITS, IAND, IOR, etc.)
Out of curiosity, what would you expect a 1-bit integer to do? In Fortran, all integers are signed, so there are no bits left for value. (There had also been proposals for unsigned integers which also failed.)
Out of curiosity, what would you expect a 1-bit integer to do? In Fortran, all integers are signed, so there are no bits left for value. (There had also been proposals for unsigned integers which also failed.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Though I had never given it thought before, I guess my colleague'sthought was to have an unsigned 1 bit integer that would only have a range of 0 - 1 to use as a sort of boolean while requiringthe least amount of memory. Just a thought. Thanks for the quick reply!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Though I had never given it thought before, I guess my colleague'sthought was to have an unsigned 1 bit integer that would only have a range of 0 - 1 to use as a sort of boolean while requiringthe least amount of memory. Just a thought. Thanks for the quick reply!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You might be able to define a user defined type and then define operators for your bit fields
Defining a (first/next) defines a variable that is not a bit field, rather it defines, possibly as parameter, an index into a bit array. The operators on the user defined type would use the index into the bit array.
While the declarations of these bit variables may be funky (could be eased using FPP macro) the use within the code would be as easy to read as using current (larger) integers/logicals.
LOGICAL(1) :: flag ! 8-bits
might be as easy to use, unless you have bazillions of these flags
Jim
Defining a (first/next) defines a variable that is not a bit field, rather it defines, possibly as parameter, an index into a bit array. The operators on the user defined type would use the index into the bit array.
While the declarations of these bit variables may be funky (could be eased using FPP macro) the use within the code would be as easy to read as using current (larger) integers/logicals.
LOGICAL(1) :: flag ! 8-bits
might be as easy to use, unless you have bazillions of these flags
Jim

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