views:

51

answers:

1

I have a homework question regarding operator precedence in Fortran. In order to understand the question I need to know how to use binary numbers in Fortran. Can someone give me an example of how to use binary numbers in fortran? (Specifically with subtraction).

+2  A: 

You need to be a bit clearer about what you mean by 'binary numbers in fortran'. In one sense, not terribly useful, all Fortran numbers are binary, as indeed most numbers in most programming languages are binary once they get onto the computer.

Fortran, in the standard at least, does not have the concept of a binary intrinsic data type, it has integers, reals, complex numbers, logicals and characters. Of course, your compiler might implement other types as well, but you don't tell us what that compiler is.

Standard Fortran does have the concept of binary input and output formats -- look for the 'B edit descriptor' in your documentation. This can be used on input and output to read and write binary representations of integers. But the numbers are, to Fortran, integers. So, if you were to read a, b as binary numbers, you would subtract them with the statement a-b.

Fortran does have a set of bit intrinsic procedures, which go by the names iand, ibclr, ieor and so forth but these are really for bit-twiddling.

If you can clarify your questions, I, or some other SOer, might be able to clarify an answer.

Finally, I think it's rather odd that you think you need to know about Fortran 'binary' numbers in order to understand operator precedence. Perhaps you could explain a bit more.

High Performance Mark
Super, thanks for the response that answers anything that I could have been asking.
sixtyfootersdude