Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Signedness

From Wikipedia, the free encyclopedia

In computing,signedness is a property ofdata types representingnumbers in computer programs. A numeric variable issigned if it can represent bothpositive andnegative numbers, andunsigned if it can only representnon-negative numbers (zero or positive numbers).

Assigned numbers can represent negative numbers, they lose a range of positive numbers that can only be represented withunsigned numbers of the same size (in bits) because roughly half the possiblevalues are non-positive values, whereas the respective unsigned type can dedicate all the possible values to the positive number range.

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

In programming languages

[edit]

For most architectures, there is no signed–unsigned type distinction in themachine language. Nevertheless,arithmetic instructions usually set differentCPU flags such as thecarry flag for unsigned arithmetic and theoverflow flag for signed. Those values can be taken into account by subsequentbranch or arithmetic commands.

TheC programming language, along with its derivatives, implements a signedness for allinteger data types, as well as for"character". For Integers, theunsigned modifier defines the type to be unsigned. The default integer signedness outside bit-fields is signed, but can be set explicitly withsigned modifier. By contrast, the C standard declaressigned char,unsigned char, andchar, to bethree distinct types, but specifies that all three must have the same size and alignment. Further,char must have the same numeric range as eithersigned char orunsigned char, but the choice of which depends on the platform. Integerliterals can be made unsigned withU suffix.

Compilers often issue a warning when comparisons are made between signed and unsigned numbers or when one iscast to the other. These are potentially dangerous operations as the ranges of the signed and unsigned types are different.

Data types
BitsMinMax
8 (signed)−128127
16 (signed)−3276832767
32 (signed)−21474836482147483647
64 (signed)−92233720368547758089223372036854775807
128 (signed)−170141183460469231731687303715884105728170141183460469231731687303715884105727
8 (unsigned)0255
16 (unsigned)065535
32 (unsigned)04294967295
64 (unsigned)018446744073709551615
128 (unsigned)0340282366920938463463374607431768211455

See also

[edit]

External links

[edit]
Uninterpreted
Numeric
Pointer
Text
Composite
Other
Related
topics
Retrieved from "https://en.wikipedia.org/w/index.php?title=Signedness&oldid=1254080479"
Categories:

[8]ページ先頭

©2009-2025 Movatter.jp