Java的按位与双和int值之间的合作 [英] Java Bitwise AND operation between a double and int value

查看:564
本文介绍了Java的按位与双和int值之间的合作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个纬度值双倍,我想它后面的位右移执行按位与操作。以下是我的code线:

I have a latitude value as double and I want to perform a Bitwise AND operation on it followed by right shift of bits. Following is my line of code:

pBuffer[1]=(latitude_decimal_degrees & 0xFF0000) >> 16;

不过按位与双和int值之间的合作是不可能的。我不能转换纬度为int,因为这不会产生一个精确的数值。任何人都可以指导我在这?

However a Bitwise AND operation between a double and int value is not possible. I cannot convert the latitude to int as this would not yield an accurate value. Can anybody guide me in this?

编辑:我的要求基本上是翻译以下vb.net code到Java。原因:code下面的线(vb.net)是写在Basic4Android对于一个Android应用程序的方法的一部分。确切的同样的方法在我的黑莓应用程序进行实施。因此,我需要有下面这产生完全相同的价值将在服务器端的德codeD:

My requirement is basically to translate the following vb.net code into java. Reason: The lines of code below (vb.net) is part of a method written in "Basic4Android" for an android app. The exact same method is to be implement in my BlackBerry App. Therefore I need to have the exact same value generated as below which will be decoded at the server end:

Dim pBuffer(11) As Int
Dim longitude_decimal_degrees As Double
pBuffer(1)=Bit.ShiftRight(Bit.And(latitude_decimal_degrees, 0xFF0000),16)

如何code,这些线路被翻译成Java?

How can these lines of code be translated into java?

推荐答案

您可以通过使用位打开双成一个长<一个href=\"http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Double.html#doubleToRawLongBits%28double%29\"相对=nofollow> Double.doubleToRawLongBits(latitude_decimal_degrees)在漫长的太空执行所有位操作,然后通过longBitsToDouble转换回双

You can turn the double into a long via bits using Double.doubleToRawLongBits(latitude_decimal_degrees) perform all bitwise operations in the long space, then convert back to a double via longBitsToDouble

另请参见本SO回答: http://stackoverflow.com/a/4211117/504685

See also this SO answer: http://stackoverflow.com/a/4211117/504685

这篇关于Java的按位与双和int值之间的合作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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