English 中文(简体)
Long number Removing First Bi -spe Way JAVA
原标题:Long Number Removing First Bit - Fast Way JAVA
  • 时间:2012-04-25 20:48:58
  •  标签:
  • java

我有一系列很长的阵容。 我想逐个增加,希望获得第一线,根据第一线,我想处理其他界限。 同仿照假守则,

i = 1000000 ;
long[] a = new long[i];
for j = 0  to i
 do,
  get long lo = a[i];

  // get first bit of lo

  if first bit = 0
     print long number (by removing first bit) in file a1

  else 
     print long number (by removing first bit) in file a2

谁能帮助我,什么是最快的方法,是“把这个长点的第一线get住”和“搬走第一线和获得数字”?

最佳回答

范围为1号。

long temp = a[i];
int bit = (temp >> 63) & 1;

这将把人数改变在63个地方和两个地点,以及1个。 如果借方为1和0,则为1。

如果你想要达到最低点,那么你就不需要转变。

int bit = temp & 1;
问题回答

tw249对我进行测试,但在此对你问题的其他部分作了回答:

long longWithoutTheFirstBit = a[i] & 0x7fffffff;

时间长是8个按部位数,这样一来,你就能够做。


long l = ...
long firstBit = l & 0x80000000; // this will be 0 if the first bit is 0

了解到在两条补充中,第一线是个标线。

在没有第一轨道的情况下获得数字——首先 您

long noFirstBit = l & 0x7FFFFFFF

第一种轨道: number >>>63——第3版通知和编号: 转移权利!

删除第1轨:<代码>编号和编号;~(1L <<63)





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...