如何使用Bitxor双号码? [英] How to use Bitxor for Double Numbers?

查看:139
本文介绍了如何使用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双号码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆