- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
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?
- Balises:
- Intel® Fortran Compiler
1 Solution
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
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.)
Lien copié
4 Réponses
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
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.)
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
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!
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
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!
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
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
Répondre
Options du sujet
- S'abonner au fil RSS
- Marquer le sujet comme nouveau
- Marquer le sujet comme lu
- Placer ce Sujet en tête de liste pour l'utilisateur actuel
- Marquer
- S'abonner
- Page imprimable