C#中如何求数字的相反数?

发布于 2024-12-15 05:13:14 字数 222 浏览 7 评论 0原文

我不确定我正在尝试的操作的名称是什么,但我想“翻转”给定范围内的数字值。

我有一个 C# 程序,它接收一个从 1 到 1023 之间的任何值的数字。我如何“翻转”该数字,以便如果我收到 1023,那么它会是 1,750 会是 274,512 仍然会是 512因为它正好是一半?

我正在考虑使用某种类型的循环,但我从未做过这样的事情。例如,我的研究发现人们想要将 40 变成 04,但这不是我想要的。

I'm not sure what the name is for the operation I am attempting, but I would like to "flip" the value of a number within a given range.

I have a C# program that receives a number that varies from any value from 1 to 1023. How would I "flip" the number so that if I receive 1023 then it would be 1, 750 would be 274, and 512 would still be 512 since its exactly half?

I was thinking of using some type of loop but I have never done anything like this. My research came up with people wanting to, for example, turn 40 into 04, but that's not what I am looking for.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白馒头 2024-12-22 05:13:14

如果您输入的数字是 x,那么您的答案就是表达式 1024-x

一般来说,如果您的数字在 1 到 max 范围内,那么答案将为 (max+1) -x

If your input number is x then your answer is the expression 1024-x

In general, if you have numbers in the range of 1 to max, then the answer would be (max+1)-x

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文