Fortran:二进制减法(有二进制类型吗?)
我有一个关于 Fortran 中运算符优先级的家庭作业问题。为了理解这个问题,我需要知道如何在 Fortran 中使用二进制数。有人可以给我一个如何在 Fortran 中使用二进制数的例子吗? (特别是减法)。
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).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要更清楚“fortran 中的二进制数”的含义。从某种意义上说,并不是很有用,所有 Fortran 数字都是二进制的,因为实际上大多数编程语言中的大多数数字一旦进入计算机就是二进制的。
Fortran,至少在标准中,没有二进制内在数据类型的概念,它有整数、实数、复数、逻辑数和字符。当然,您的编译器也可能实现其他类型,但您没有告诉我们该编译器是什么。
标准 Fortran 确实有二进制输入和输出格式的概念——在文档中查找“B 编辑描述符”。这可以用于输入和输出来读取和写入整数的二进制表示。但对于 Fortran 语言来说,这些数字是整数。因此,如果您要将
a, b
读取为二进制数,则可以使用语句ab
将它们相减。Fortran 确实有一组位内部过程,其名称为 iand、ibclr、ieor 等等,但这些实际上是用于位操作的。
如果您能澄清您的问题,我或其他一些 SOer 或许能够澄清答案。
最后,我认为您认为需要了解 Fortran“二进制”数字才能理解运算符优先级是相当奇怪的。也许你可以多解释一下。
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 statementa-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.