signed

Convert unsigned byte to signed byte

核能气质少年 提交于 2019-12-18 04:44:13
问题 Is there an easy and elegant way to convert an unsigned byte value to a signed byte value in java? For example, if all I have is the int value 240 (in binary (24 bits + 11110000) = 32bits), how can I get the signed value for this int? 回答1: Java does not have unsigned values, except for char . Consider this snippet: byte val = (byte)255; System.out.println(String.valueOf(val)); The result will be -1, because the lowest 8 bits got copied over to the byte variable. 回答2: In Java all the primitive

Difference between char and signed char in c++?

允我心安 提交于 2019-12-18 03:03:18
问题 Consider the following code : #include <iostream> #include <type_traits> int main(int argc, char* argv[]) { std::cout<<"std::is_same<int, int>::value = "<<std::is_same<int, int>::value<<std::endl; std::cout<<"std::is_same<int, signed int>::value = "<<std::is_same<int, signed int>::value<<std::endl; std::cout<<"std::is_same<int, unsigned int>::value = "<<std::is_same<int, unsigned int>::value<<std::endl; std::cout<<"std::is_same<signed int, int>::value = "<<std::is_same<signed int, int>::value

Unsigned and Signed Values in C (Output)

情到浓时终转凉″ 提交于 2019-12-18 01:05:28
问题 signed int x = -5; unsigned int y = x; What is the value of y ? How is this so? 回答1: It depends on the maximum value of the unsigned int . Typically, a unsigned int is 32-bit long, so the UINT_MAX is 2 32 − 1. The C standard (§6.3.1.3/2) requires a signed → unsigned conversion be performed as Otherwise, if the new type is unsigned, the value is converted by repeatedly adding or subtracting one more than the maximum value that can be represented in the new type until the value is in the range

signed applet gives AccessControlException: access denied, when calling from javascript

自作多情 提交于 2019-12-17 20:26:02
问题 I have an easy self-signed an applet (done with keytool and the jarsigner): public class NetAppletLauncher extends JApplet { private static final long serialVersionUID = 1L; public void init() { exec("notepad c:/hello.txt"); } public void exec(String command) { try { // launch EXE and grab stdin/stdout and stderr Process process = Runtime.getRuntime().exec(command); // OutputStream stdin = process.getOutputStream(); InputStream stderr = process.getErrorStream(); InputStream stdout = process

Has anyone got any code to call SignerSignEx from C#?

我与影子孤独终老i 提交于 2019-12-17 16:44:13
问题 Would really appreciate something that does the .Net equivalent of the SignerSignEx example here: http://blogs.msdn.com/b/alejacma/archive/2008/12/11/how-to-sign-exe-files-with-an-authenticode-certificate-part-2.aspx?CommentPosted=true Thanks!!!!!!! 回答1: I got it working. If anyone's interested, here's the code - it probably needs a little more work to make it production-ready, but it works for me :) using System; using System.Runtime.InteropServices; using System.Security.Cryptography

Why does this if condition fail for comparison of negative and positive integers [duplicate]

*爱你&永不变心* 提交于 2019-12-17 14:47:12
问题 This question already has answers here : sizeof() operator in if-statement (5 answers) Closed last year . #include <stdio.h> int arr[] = {1,2,3,4,5,6,7,8}; #define SIZE (sizeof(arr)/sizeof(int)) int main() { printf("SIZE = %d\n", SIZE); if ((-1) < SIZE) printf("less"); else printf("more"); } The output after compiling with gcc is "more" . Why the if condition fails even when -1 < 8 ? 回答1: The problem is in your comparison: if ((-1) < SIZE) sizeof typically returns an unsigned long , so SIZE

How to convert signed to unsigned integer in python

*爱你&永不变心* 提交于 2019-12-17 08:28:07
问题 Let's say I have this number i = -6884376 . How do I refer to it as to an unsigned variable? Something like (unsigned long)i in C. 回答1: Assuming : You have 2's-complement representations in mind; and, By (unsigned long) you mean unsigned 32-bit integer, then you just need to add 2**32 (or 1 << 32) to the negative value. For example, apply this to -1: >>> -1 -1 >>> _ + 2**32 4294967295L >>> bin(_) '0b11111111111111111111111111111111' Assumption #1 means you want -1 to be viewed as a solid

Why does -INT_MIN = INT_MIN in a signed, two's complement representation?

谁都会走 提交于 2019-12-17 05:11:48
问题 I still haven't found a reason why the lowest signed negative number doesn't have an equivalent signed positive number? I mean in a 3 digit binary number for simplicity 100 is -4? but we can't have a positive 4 in signed format because we can't. It overflows. So how do we know two's complement 1000 is -4 1000 0000 is -128 and so on? We have no original positive number 回答1: One way to think about it is that signed, two's complement format works by assigning each bit a power of two, then

Signed versus Unsigned Integers

社会主义新天地 提交于 2019-12-17 02:02:27
问题 Am I correct to say the difference between a signed and unsigned integer is: Unsigned can hold a larger positive value, and no negative value. Unsigned uses the leading bit as a part of the value, while the signed version uses the left-most-bit to identify if the number is positive or negative. signed integers can hold both positive and negative numbers. Any other differences? 回答1: Unsigned can hold a larger positive value, and no negative value. Yes. Unsigned uses the leading bit as a part

Is this an unavoidable signed and unsigned integer comparison?

廉价感情. 提交于 2019-12-13 20:04:52
问题 Probably not, but I can't think of a good solution. I'm no expert in C++ yet. Recently I've converted a lot of int s to unsigned int s in a project. Basically everything that should never be negative is made unsigned. This removed a lot of these warnings by MinGW: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] I love it. It makes the program more robust and the code more descriptive. However, there is one place where they still occur. It looks like this: