What is the concept of integers signed in a programming language?

Asked

Viewed 712 times

6

I would like to clarify the meaning of the term "whole signed".

I’m researching protocols, to build one in Java, and sometimes I find the term. I don’t know what it’s about.

I’ve always heard of primitive types, for example in Java: int, float, double, ...

But for me the term is new!

Why is it said that Java "does not have" such unsigned integer?

And what’s the difference between a "signed integer" and an "unsigned integer"?

  • I believe java does have signed integers, what it does not have are unsigned integers.

  • Do you need something better? Do you think you can accept it now?

1 answer

11

If signed whole is meaning checked integer, it is the type normally used in Java. The number has a bit to indicate whether it is positive or negative.

Many languages have signal-less types where this bit is not considered, so it only holds positive numbers, but can go up to twice the same signal type. Java is not one of these languages. They considered this to be a simplification in the language.

It even makes sense because it is common for people to use it wrong and in few situations they are needed in high-level applications. But where you need it, you can’t use it, if you need to interfere with external code you’ll have difficulties.

In C#, for example there is ushort (goes up to 65535), uint (up to 4294836225) ulong (until 18445618199572250625), with the byte (up to 255) is no longer signalled, and the sbyte is wearing a sign.

So the sign described there is the + or -.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.