signed

Signed equivalent of a 2's complement hex value

南笙酒味 提交于 2019-12-24 05:38:30
问题 On the python terminal when I do :- In [6]: 0xffffff85 Out[6]: 4294967173 In [9]: "%d" %(0xffffff85) Out[9]: '4294967173' I'd like to be able to give in 0xffffff85 and get the signed equivalent decimal number in python(in this case -123 ). How could I do that? In C, I could do it as :- int main() { int x = 0xffffff85; printf("%d\n", x); } 回答1: You could do that using ctypes library. >>> import ctypes >>> ctypes.c_int32(0xffffff85).value -123 You can also do the same using bitstring library. >

SQL Server 2005 - Format a decimal number with leading zeros (including signed decimals!)

那年仲夏 提交于 2019-12-24 04:44:28
问题 I need to format numbers like:- 1.99 21.34 1797.94 -300.36 -21.99 -2.31 Into a format mask of 0000.00, using SQL-Server 2005 T-SQL. Preserving the signed integers and the decimals after the dot. This would be used for text file exports for a financial system. It requires it to be in this format. e.g.- 0001.99 0021.34 1794.94 -0300.36 -0021.99 -0002.31 Previously, it was done in MS Access as Format([Total],"0000.00") but SQL-Server doesn't have this function. 回答1: ;WITH t(c) AS ( SELECT 1.99

PHP filesize() On Files > 2 GB

 ̄綄美尐妖づ 提交于 2019-12-23 12:00:31
问题 I have been struggeling on how to get the valid filesize of a file that is >= 2 GB in PHP. Example Here I am checking the filesize of a file that is 3,827,394,560 bytes large with the filesize() function: echo "The file is " . filesize('C:\MyFile.rar') . " bytes."; Result This is what it returns: The file is -467572736 bytes. Background PHP uses signed integers, which means that the maximum number it can represent is 2,147,483,647 (+/- 2 GB). This is where it is limited. 回答1: http://us.php

Unsigned versus signed numbers as indexes

微笑、不失礼 提交于 2019-12-23 07:30:18
问题 Whats the rationale for using signed numbers as indexes in .Net? In Python, you can index from the end of an array by sending negative numbers, but this is not the case in .Net. It's not easy for .Net to add such a feature later as it could break other code perhaps using special rules (yeah, a bad idea, but I guess it happens) on indexing. Not that I have ever have needed to index arrays over 2,147,483,647 in size, but I really cannot understand why they choose signed numbers. Can it be

Unsigned versus signed numbers as indexes

扶醉桌前 提交于 2019-12-23 07:30:05
问题 Whats the rationale for using signed numbers as indexes in .Net? In Python, you can index from the end of an array by sending negative numbers, but this is not the case in .Net. It's not easy for .Net to add such a feature later as it could break other code perhaps using special rules (yeah, a bad idea, but I guess it happens) on indexing. Not that I have ever have needed to index arrays over 2,147,483,647 in size, but I really cannot understand why they choose signed numbers. Can it be

Convert a string to an 8-bit signed integer in python

柔情痞子 提交于 2019-12-23 04:56:10
问题 I'm trying to patch together a motor control system using python and ctypes and one of the things I need to do is take an text input and convert it to an 8-bit signed integer. Below is the documentation for the function I'm trying to call. The text that should be input into the program is 'EPOS2' The data type definition is as shown below (note that 'char*' equates to an 8-bit signed integer) So How do I convert 'EPOS2' to a value between -128 and 127? Ultimately what I'm trying to do is

Using ruby to convert unsigned integers stored as signed back to the original value

冷暖自知 提交于 2019-12-22 13:53:05
问题 A C-program is placing what it considers to be 64-bit unsigned integers into a column in a Postgres database that is typed as int8. To Postgres, int8 is always 'signed int8' (no such thing to it as 'unsigned int8'). So the Ruby program I have shows numbers retrieved from Postgres in the upper half of that space as negative. What is the correct way, in Ruby, to take that -ve integer and convert it to the 64-bit unsigned integer that the C-programmer intended? 回答1: I'm not sure of Ruby

Spring Component Scan (@Autowire) in signed Jar Files is slow

*爱你&永不变心* 提交于 2019-12-22 10:29:08
问题 Years ago we had a problem with slow Spring component scans in standalone java applications so I asked in stackoverflow: Slow spring component scan . Years later I stumbled again about this problem and I think I found out why it is slow: It is because the jar files are signed. Currently we have about 170 jar files in our app. Our own and 3rd party. We sign all of them. Usually we use webstart and the performance for the component scan is ok. Starting our app with a huge classpath by just

How does adding MIN_VALUE compare integers as unsigned?

。_饼干妹妹 提交于 2019-12-22 04:46:07
问题 In Java the int type is signed, but it has a method that compares two ints as if they were unsigned: public static int compareUnsigned(int x, int y) { return compare(x + MIN_VALUE, y + MIN_VALUE); } It adds Integer.MIN_VALUE to each argument, then calls the normal signed comparison method, which is: public static int compare(int x, int y) { return (x < y) ? -1 : ((x == y) ? 0 : 1); } How does adding MIN_VALUE to each argument magically make the comparison unsigned? 回答1: This technique works

Why must loop variables be signed in a parallel for?

北慕城南 提交于 2019-12-21 12:30:47
问题 I'm just learning OpenMP from online tutorials and resources. I want to square a matrix (multiply it with itself) using a parallel for loop. In IBM compiler documentation, I found the requirement that "the iteration variable must be a signed integer." Is this also true in the GCC implementation? Is it specified in the OpenMP standard? If so, is there a reason for this requirement? (It doesn't matter much as the expected dimensions are far smaller than INT_MAX , but it does cost me some casts.