Questions tagged [signed]

In computing, signedness is a property of data types representing numbers in computer programs.

A numeric variable is signed if it can represent both positive and negative numbers, and unsigned if it can only represent non-negative numbers (zero or positive numbers).

As signed numbers can represent negative numbers, they lose a range of positive numbers that can only be represented with unsigned numbers of the same size (in bits) because roughly half the possible values are non-positive values. Unsigned variables can dedicate all the possible values to the positive number range.

For example, a Two's complement signed 16-bit integer can hold the values −32768 to 32767 inclusively, while an unsigned 16 bit integer can hold the values 0 to 65535. For this sign representation method, the leftmost bit (most significant bit) denotes whether the value is positive or negative (0 for positive, 1 for negative).

Reference

980 questions
12
votes
5 answers

Convert Raw 14 bit Two's Complement to Signed 16 bit Integer

I am doing some work in embedded C with an accelerometer that returns data as a 14 bit 2's complement number. I am storing this result directly into a uint16_t. Later in my code I am trying to convert this "raw" form of the data into a signed…
secretformula
  • 6,414
  • 3
  • 33
  • 56
12
votes
1 answer

Can the Postgres data type NUMERIC store signed values?

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?
Nyi Ma Lay Win Lae Aye
  • 6,250
  • 2
  • 13
  • 10
12
votes
2 answers

16 bit hex string to signed int in Java

I have a string in Java representing a signed 16-bit value in HEX. This string can by anything from "0000" to "FFFF". I use Integer.parseInt("FFFF",16) to convert it to an integer. However, this returns an unsigned value (65535). I want it to return…
dimme
  • 4,393
  • 4
  • 31
  • 51
11
votes
1 answer

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

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!!!!!!!
Kram
  • 4,099
  • 4
  • 39
  • 60
11
votes
2 answers

Converting hexadecimal numbers in strings to negative numbers, in Perl

I have a bunch of numbers represented as hexadecimal strings in log files that are being parsed by a Perl script, and I'm relatively inexperienced with Perl. Some of these numbers are actually signed negative numbers, i.e. 0xFFFE == -2 when…
Alex Marshall
  • 10,162
  • 15
  • 72
  • 117
11
votes
5 answers

How can I do 64-bit arithmetic in Perl?

I am a perl newbie, Can I simply use 64-bit arithmetic in Perl? For example $operand1 = 0xFFFFFFFFFFFF; # 48 bit value $operand2 = 0xFFFFFFFFFFFF; # 48 bit value $Result = $operand1 * $operand2; I am basically looking for a replacement for…
Alphaneo
  • 12,079
  • 22
  • 71
  • 89
11
votes
3 answers

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

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]
Claudiu
  • 224,032
  • 165
  • 485
  • 680
11
votes
2 answers

How do I read the digital signature information from a signed .Net assembly?

I am writing an assembly information application to be used in our software build process and am trying to read the digital signature information from a signed .Net assembly. I want to do in my C# code what Windows Explorer can do by right-clicking…
VinceJS
  • 1,254
  • 3
  • 18
  • 38
10
votes
5 answers

what's the point using unsigned int in C?

I thought that unsigned int could store only integers >= 0. But I tried assigning a negative to an unsigned int, nothing special happened. It seems like it stored the value with no problem. So what is the difference between signed and unsigned int,…
Danny
  • 125
  • 1
  • 7
10
votes
6 answers

How to print a signed integer as hexadecimal number in two's complement with python?

I have a negative integer (4 bytes) of which I would like to have the hexadecimal form of its two's complement representation. >>> i = int("-312367") >>> "{0}".format(i) '-312367' >>> "{0:x}".format(i) '-4c42f' But I would like to see "FF..."
none
  • 103
  • 1
  • 1
  • 4
10
votes
3 answers

Conversion from char* to signed char*

I saw a piece of valid C code I tried to compile as C++ and I got an error I can't understand. char* t; signed char* v = t; error: invalid conversion from char* to signed char* From what I learned, char and signed char are semantically identical,…
Jaffa
  • 12,442
  • 4
  • 49
  • 101
10
votes
10 answers

2's complement example, why not carry?

I'm watching some great lectures from David Malan (here) that is going over binary. He talked about signed/unsigned, 1's compliment, and 2's complement representations. There was an addition done of 4 + (-3) which lined up like this: 0100 1101 (flip…
Alex Mcp
  • 19,037
  • 12
  • 60
  • 93
9
votes
2 answers

How to trust a certificate in Windows Powershell

I am using Windows 7, and want to run signed scripts from Powershell, the security-settings of Powershell are set to "all-signed", and my scripts are signed with a valid certificate from my company. I have also added the .pfx-file to my local…
Erik
  • 2,316
  • 9
  • 36
  • 58
9
votes
3 answers

How to judge an overflow when adding signed to unsigned

I'm trying to detect the overflow when adding a signed offset to an unsigned position uint32 position; int32 offset; // it could be negative uint32 position = position+offset; How can I check whether the result is overflow or underflow? I have…
rogerz
  • 1,073
  • 9
  • 18
9
votes
5 answers

Convert unsigned byte to signed byte

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?
Joeblackdev
  • 7,217
  • 24
  • 69
  • 106