java双与,Java的按位与双和int值之间的合作

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;

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?

EDIT: 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)

How can these lines of code be translated into java?

解决方案

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值