convert int to short

Jarrett Billingsley jarrett.billingsley at gmail.com
Wed Oct 29 05:23:51 PDT 2008


On Wed, Oct 29, 2008 at 4:17 AM, James <james at gmail.com> wrote:
> can anybody tell me how to convert int value to short since normal type-casting would return diff value (im not familiar with bit-shift, etc.)
>

It's... it's called the pigeonhole principle.  You have too many
things to put into too few slots.  A short can only hold one of 65,536
distinct values, whereas an int can hold over 4 billion.  You just
can't put 4 billion things into 65,536 slots.  So yes, for all but
numbers in the range that a short can hold, casting will give you a
different value.


More information about the Digitalmars-d-learn mailing list