C#中如何求数字的相反数?
我不确定我正在尝试的操作的名称是什么,但我想“翻转”给定范围内的数字值。
我有一个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您输入的数字是 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