signed

What is the deal with assigning an unsigned variable to a signed value?

六眼飞鱼酱① 提交于 2020-01-11 14:12:09
问题 This code I am looking at has a lot of places where I see things like this happening: char *functionName(char *passedVariable) { unsigned char *newVariable = (char* ) passedVariable; Why is this being done? I always try to be consistent in the use of signed/unsigned, because I know that switching between the two can cause problems, but this developer doesn't seem to care. 回答1: Changing the pointer type is not really an issue, this address will still be valid. However interpreting the pointed

Is INT_MAX+1 = INT_MIN in signed integer? [duplicate]

痞子三分冷 提交于 2020-01-03 06:51:10
问题 This question already has answers here : for every int x: x+1 > x … is this always true? (4 answers) Closed 6 years ago . for (i = 0; i <= N; ++i) { ... } This particular statement will cause an infinite loop if N is INT_MAX . Having known that Unsigned Overflows are wrapping overflows, assuming i and N to unsigned, compiler can assume that the loop will iterate exactly N+1 times if i is undefined on overflow. The thing to note here is: if I make the loops as, for (i = 0; i < N; ++i) { ... }

Byte Array to *Signed* Int

无人久伴 提交于 2020-01-03 04:28:07
问题 I'm trying to convert -101 to a byte array and then convert the byte array back to -101 . My methods below work for positive values but not for negative values. Can you suggest what I'm doing wrong? Instead of -101 , the byteArrayToInt method returns 65435 . Thanks! /** * Converts a <code>byte</code> array to a 32-bit <code>int</code>. * * @param array The <code>byte</code> array to convert. * @return The 32-bit <code>int</code> value. */ public static int byteArrayToInt(byte[] array) {

Signed Java Applet Throws Security Exception on Connect to a Webservice

南笙酒味 提交于 2020-01-03 02:57:20
问题 I have an java applet running on tomcat 5.5. It is signed ( -selfcert). I still get an java.security.AccessControlException: access denied (java.lang.RuntimePermission createClassLoader) Exception, when my Applet tries to connect to a webservice (already in this line): ws_locator = new My_WebserviceLocator(ws_adress + "?wsdl", new javax.xml.namespace.QName("http://impl.webservice", "My_Webservice")); Since there are some similar questions here, an i read them: Yes, the applet is signed. I

C# Unsigned bytes Encryption to Java Signed bytes Decryption

纵然是瞬间 提交于 2019-12-31 03:17:26
问题 I have an application in C# that encrypt part of my files (because they are big files) using RijndaelManaged. So I convert my file to byte arrays and encrypt only a part of it. Then I want to decrypt the file using Java. So I have to decrypt only part of the file (means those bytes) that was encrypted in C#. Here the problem comes. Because in C# we have unsigned bytes and in Java we have signed bytes . So my encryption and decryption not working the way I want. In C# I have joined the

How to convert signed 32-bit int to unsigned 32-bit int?

北慕城南 提交于 2019-12-30 06:11:28
问题 This is what I have, currently. Is there any nicer way to do this? import struct def int32_to_uint32(i): return struct.unpack_from("I", struct.pack("i", i))[0] 回答1: Not sure if it's "nicer" or not... import ctypes def int32_to_uint32(i): return ctypes.c_uint32(i).value 回答2: using numpy for example: import numpy result = numpy.uint32( numpy.int32(myval) ) or even on arrays, arr = numpy.array(range(10)) result = numpy.uint32( numpy.int32(arr) ) 来源: https://stackoverflow.com/questions/16452232

Can the Postgres data type NUMERIC store signed values?

此生再无相见时 提交于 2019-12-29 08:36:13
问题 In PostgreSQL, I would like to store signed values -999.9 - 9999.9 . Can I use numeric(5.1) for this? Or what type should I use? 回答1: You can certainly use the arbitrary precision type numeric with a precision of 5 and a scale of 1, just like @Simon commented, but without the syntax error. Use a comma( , ) instead of the dot ( . ) in the type modifier: SELECT numeric(5,1) '-999.9' AS nr_lower , numeric(5,1) '9999.9' AS nr_upper; nr_lower | nr_upper ----------+---------- -999.9 | 9999.9 The

Signed Integer Network and Host Conversion

本小妞迷上赌 提交于 2019-12-29 06:17:35
问题 I would like to convert a int32_t from host byte order to network byte order and vice versa. I know about the htonl() function and its variants, but this takes unsigned integers. Is there a standard library function which can do the same with signed integers or do I have to implement it myself? And if I have to implement it myself, how should I do it? I'm looking to find a routine that will work on Linux and Mac OS X. 回答1: It does not matter. htonl is concerned with bytes, not with

Java negative int to hex and back fails

风格不统一 提交于 2019-12-28 06:22:07
问题 public class Main3 { public static void main(String[] args) { Integer min = Integer.MIN_VALUE; String minHex = Integer.toHexString(Integer.MIN_VALUE); System.out.println(min + " " + minHex); System.out.println(Integer.parseInt(minHex, 16)); } } Gives -2147483648 80000000 Exception in thread "main" java.lang.NumberFormatException: For input string: "80000000" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48) at java.lang.Integer.parseInt(Integer.java:459) at

portable signed/unsigned byte cast,C++

时光怂恿深爱的人放手 提交于 2019-12-24 07:43:23
问题 I am using signed to unsigned byte(int8_t) cast to pack byts. uint32_t(uint8_t(byte)) << n This works using GCC on Intel Linux. Is that portable for other platforms/compilers, for example PowerPC? is there a better way to do it? using bitset is not possible in my case. I am using stdint via boost 回答1: If you are using boost/cstdint.hpp from the Boost Integer library, then yes, the typedefs are portable (cross-platform.) The boost/cstdint.hpp header is meant to implement C99 stdint.h