好吧,所以我有4个整数,我想包裹很长一段时间.4个整数都包含3个值,位于前2个字节中:
+--------+--------+
|xxpppppp|hdcsrrrr|
+--------+--------+
Run Code Online (Sandbox Code Playgroud)
{pppppp}代表一个值,{hdcs}代表第二个值,{rrrr}代表最后一个值.
我想在很长一段时间内打包4个这样的整数.我尝试过以下方法:
ordinal = (c1.ordinal() << (14*3) | c2.ordinal() << (14*2) | c3.ordinal() << 14 | c4.ordinal());
Run Code Online (Sandbox Code Playgroud)
其中c1.ordinal()... c4.ordinal()是要包装的整数.
如果我运行测试,这似乎不起作用.假设我想查找long中最后一个整数的值c4.ordinal(),其中{pppppp} = 41,{hdcs} = 8且{rrrr} = 14,我得到以下结果:
System.out.println(c4.ordinal() & 0xf); //Prints 14
System.out.println(hand.ordinal() & 0xf); // Prints 14 - correct
System.out.println(c4.ordinal() >> 4 & 0xf); // Prints 8
System.out.println(hand.ordinal() >> 4 & 0xf); // Prints 8 - correct
System.out.println(c4.ordinal() >> 8 & 0x3f); // Prints 41
System.out.println(hand.ordinal() >> 8 & 0x3f); // Prints 61 - …Run Code Online (Sandbox Code Playgroud) 我有一个很长的整数变量,它保存数据 20101201
我需要把它拆分为2010,12和01.
注意:我需要在我的linux机器上的C程序中执行此操作.
在我的类中我有一个属性,fileSize 类型很长
我不想更改为float/double,因为我使用数据库,现在我不能只编辑数据类型(到了晚)
文件大小通常是以KB为单位(理由为什么长)..但是一旦我想以MB显示它(即fileSize/1024) - >我得到0,因为类型不是float/double ..
我如何解决问题,以便在不更改fileSize的DataType的情况下获得0.54MB的bE?
这个数字属于长距离,为什么我会收到错误:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The literal 8751475143 of type int is out of range
Run Code Online (Sandbox Code Playgroud) String avgPageLoadTimeStr = row.get("avg_page_load_time");
Long avgPageLoadTime = Long.parseLong(avgPageLoadTimeStr);
Run Code Online (Sandbox Code Playgroud)
例如 :
avgPageLoadTimeStr = 52747.50;
Run Code Online (Sandbox Code Playgroud)
如何转换avgPageLoadTimeStr为Long?
好像标题所说,我必须转换double[]为a long[]但我不知道我该怎么做.
我试试这个:
double[] ids = getIds(); // The ids I'm getting return in double format
List<Long> myArray = new ArrayList<Long>();
for (double _ids : ids) {
myArray.add((long)_ids);
}
System.out.println(myArray); // Works! the list is now long, I can print also in myArray.toArray()
// Now I need pass this on a long[] array for the system wich request the data
// Receive "getStringsById(String string, long... Ids)"
Run Code Online (Sandbox Code Playgroud)
我非常感谢你的帮助.
谢谢你的时间.
我有一个表示64位unsigned int的十六进制字符串.
我想将它转换为java中的十进制表示.
我想使用Long.parseLong("HexString", 16);但在java中最左边的位是符号位,任何大于2 ^ 31-1的数字都不适合.
那我如何转换和存储这些数据?
谢谢,Sunny
值selected_int_kind(int16)显示为1而不是2.这是编译器错误吗?
在下面的输出中请注意其差异bint是2个字节,INT16.(为清楚起见,添加了注释<===.)
compiler version = GCC version 5.1.0
compiler options = -fPIC -mmacosx-version-min=10.9.4 -mtune=core2 -Og -Wall -Wextra -Wconversion -Wpedantic -fcheck=bounds -fmax-errors=5
execution command = ./a.out
Number of bytes in type default = 4
Number of bytes in type int_8 = 1
Number of bytes in type int_16 = 2 <===
Number of bytes in type int_32 = 4
Number of bytes in type int_64 = 8
Number of bytes in type int_a = 1 …Run Code Online (Sandbox Code Playgroud) 嗨我正在尝试构建一个随机的16个字符十六进制,这样做我尝试了 Long.toHexString(new Random().nextLong()我的假设是它将始终返回一个16字符串,我是对的吗?(一旦它返回15个字符)
我有以下char序列:
char* input = "3243f6a8885a308d313198a2e0370734";
Run Code Online (Sandbox Code Playgroud)
然后我尝试从前两个字符中提取并将其input存储为如下数字:
char state_col[9];
char state_col_t[3];
memcpy(state_col, input, 8);
state_col[8] = 0;
state_col_t[0] = state_col[0]; state_col_t[1] = state_col[1]; state_col_t[2] = 0;
long int value = strtol(state_col_t, &endptr, 16);
char c_value = value;
Run Code Online (Sandbox Code Playgroud)
当我尝试打印出结果时:
printf("%x %x", c_value, value);
Run Code Online (Sandbox Code Playgroud)
我得到这个(例如):
32 32
43 43
fffffff6 f6
ffffffa8 a8
它似乎与值> 0x80有关.想法?