我试图了解Java如何在内部存储整数.我知道所有java原始整数都是有符号的(除了短?).这意味着该字节的字节中可用的位数较少.
我的问题是,所有整数(正数和负数)都存储为二进制补码或只是二进制补码中的负数吗?
我看到规格说明了x bit two's complement number.但我经常感到困惑.
例如:
int x = 15; // Stored as binary as is? 00000000 00000000 00000000 00001111?
int y = -22; // Stored as two complemented value? 11111111 11111111 11111111 11101010
Run Code Online (Sandbox Code Playgroud)
编辑
要清楚, x = 15
In binary as is: `00000000 00000000 00000000 00001111'
Two's complement: `11111111 11111111 11111111 11110001`
Run Code Online (Sandbox Code Playgroud)
因此,如果您的答案是 all数字存储为两个补码,那么:
int x = 15; // 11111111 11111111 11111111 11110001
int y = -22 // 11111111 11111111 11111111 11101010
Run Code Online (Sandbox Code Playgroud)
这里的混淆再次是标志说,两者都是负数.可能是我误读/误解了吗?
编辑 …
我想在android上制作一个应用程序,它通过USB将MIDI信息发送到计算机,以便能够控制音乐软件,如Cubase,FL,Reason等...
硬件MIDI控制器(例如键盘)在Windows上的音乐软件中自动识别.我猜这是因为他们使用的是通用音乐软件直接识别的通用MIDI协议.他们不需要自己的司机.
我希望能够将我的手机/平板电脑用作midi控制器,而无需在计算机上安装人员(如硬件控制器).
在Android开发者上有一个演示代码,用于通过USB控制导弹发射器玩具.如果我发送,使用相同的技术,遵循MIDI协议的消息它会像那样工作吗?
预先感谢您的帮助
为什么以下代码会导致我的Android应用崩溃?
new String("é".getBytes(StandardCharsets.UTF_8), "UTF8")
Run Code Online (Sandbox Code Playgroud)
或者干脆
new String("é".getBytes())
Run Code Online (Sandbox Code Playgroud)
这该怎么做?
一些信息:
错误:
08-18 20:30:04.877 18914-18924/com.nextwebart.senego W/google-breakpad:### ### ### ### ### ### ### ### ### ### ### ### ### 08-18 20:30:04.877 18914-18924/com.nextwebart.senego W/google-breakpad:Chrome构建指纹:08-18 20:30:04.877 18914-18924 /com.nextwebart.senego W/google-breakpad:4.2.8 08-18 20:30:04.877 18914-18924/com.nextwebart.senego W/google-breakpad:70 08-18 20:30:04.877 18914-18924 /com.nextwebart.senego W/google-breakpad:### ### ### ### ### ### ### ### ### ### ### ### ## #08-18 20:30:04.877 18914-18924/com.nextwebart.senego A/libc:致命信号11(SIGSEGV),代码1,故障地址0x5 …