如何使用Bitxor双号码?

编程入门 行业动态 更新时间:2024-10-11 23:15:56
本文介绍了如何使用Bitxor双号码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我想在matlab中使用xor作为双数,但是bitxor只适用于int数字。有没有可以在Matlab中将double转换为int的功能?

解决方案

您正在寻找的功能可能是: int8(number), int16(number), uint32(number)任何一个都会将Double转换成整数,但是您必须选择最佳的结果,才能实现。记住,你不能从Double转换成Integer,而不舍入数字。

如果我理解你的错误,你可以创建一个函数,简单地删除逗号通过将起始值乘以2 ^ n,然后使用前面提到的任何函数将其转换为Integer,执行任何您想要的,然后通过将数字除以2 ^ n

$将逗号返回到其原始位置b $ b

将起始值乘以2 ^ n是一个将减少舍入误差的破解。 如果这个数字相对较小, n 的完美值将是逗号后面的数字。

请同时指定你为什么要这么做?这似乎不是最佳解决方案。

I want to use xor for my double numbers in matlab,but bitxor is only working for int numbers. Is there a function that could convert double to int in Matlab?

解决方案

The functions You are looking for might be: int8(number), int16(number), uint32(number) Any of them will convert Double to an Integer, but You must pick the best one for the result You want to achieve. Remember that You cannot cast from Double to Integer without rounding the number.

If I understood You correcly, You could create a function that would simply remove the "comma" from the Double number by multiplying your starting value by 2^n and then casting it to Integer using any of the functions mentioned earlier, performing whatever you want and then returning comma to its original position by dividing the number by 2^n

Multiplying the starting value by 2^n is a hack that will decrease the rounding error. The perfect value for n would be the number of digits after the comma if this number is relatively small.

Please also specify, why are You trying to do this? This doesn't seem to be the optimal solution.

更多推荐

如何使用Bitxor双号码?

本文发布于:2023-11-29 13:59:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1646589.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   双号   Bitxor

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!