signed byte

Type Range Default Value
signed byte -128 to 127 0

The signed byte type represents a 8-bit signed two's-complement integer.

Literals

Integrals without a suffix are interpreted in this order: int, unsigned int, long, unsigned long, byte, signed byte, short, unsigned short, and char. If the integral value does not "fit" within any specified types, such as possible function overloads or a specified variable type, an error will be raised at compile time.

There is no suffix for the signed byte type, and integer literals that fit within the range of the signed byte type can be written without a suffix.

Auto-boxing

All primitive types have a corresponding wrapper class. The corresponding wrapper class for the signed byte type is System.Integer8.

Auto-boxing occurs when a value of a primitive type is assigned or passed as an argument to a variable or function that expects a value of its corresponding wrapper class. For example, the integer literal 100 would fit within the range of a signed byte and can be assigned to a variable of type System.Integer8 via auto-boxing:

1
System.Integer8 value = 100; // Auto-boxing

Without auto-boxing, the equivalent code would be:

1
System.Integer8 value = new System.Integer8(100);

The reverse also occurs. Unboxing is when the wrapper class is automatically converted to its corresponding primitive type. Thus, an instance of System.Integer8 can be unboxed to the signed byte primitive type.

1
signed byte value = new System.Integer8(100); // Unboxing

Overflow and Wrapping

When values for integer types go out of range at runtime, they will "wrap around". Thus, if a variable is declared as having the signed byte type, and, at runtime, the variable's value exceeds the signed byte maximum (127) by one, it will wrap around to the signed byte minimum (-128); if the value exceeds the signed byte maximum by two, it will wrap around to the signed byte minimum plus one (-127); and so on.

Conversions for Internal Types

For conversions to and from the signed byte type, consult the Conversions Table.

Conversions for external Type

When converting from external:

  • If the external value is a numeric value, it will be automatically converted to the equivalent integer value.

  • If the external value is a numeric value that is out of range, wrapping will occur.

  • If the external value is a numeric string value, it will be automatically converted to the equivalent integer value.

  • If the external value is a numeric string value that is out of range, wrapping will occur.

  • If the external value is a non-numeric string value, it will be automatically converted to zero (0).

  • If the external value is the Boolean true value, it will be automatically converted to one (1).

  • If the external value is the Boolean false value, it will be automatically converted to zero (0).

  • If the external value is a non-numeric value and non-Boolean value, it will be automatically converted to zero (0).

When converting to external, the value will be converted to a JavaScript number value.

See Also

Share

HTML | BBCode | Direct Link