Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

1-bit integer

Glenn1
Beginner
1,595 Views
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?
0 Kudos
1 Solution
Steven_L_Intel1
Employee
1,595 Views
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.)

View solution in original post

0 Kudos
4 Replies
Steven_L_Intel1
Employee
1,596 Views
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.)
0 Kudos
Glenn1
Beginner
1,595 Views
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!
0 Kudos
Glenn1
Beginner
1,595 Views
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!
0 Kudos
jimdempseyatthecove
Honored Contributor III
1,595 Views
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


0 Kudos
Reply