[A83] Re: long to int


[Prev][Next][Index][Thread]

[A83] Re: long to int




in c, I'd go for the following:

up16 = (int) (longvar & 0xFFFF0000) >> 16;
low16 = (int) (longvar & 0xFFFF);

> 
> Ok, lets say that I have a long variable "longvar" and I want to store the
> the upper 16 bits in a variable "up16" and the lower 16 bits in a var
> "low16".
> 
> How would I do this?
> 
> Here are some of my ideas.
> 	up16 = (int)&longvar[0];
> 	low16 = (int)&longvar[2];
> 
> or
> 
> 	up16 = ((longvar & 4294901760)/65536)    //4294901760 is
> 1111,1111,1111,1111,0000,0000,0000,0000 65536 is 1,0000,0000,0000,0000
> 
> 	low16 = (longvar & 65535)
> 
> will either of these work?  Is there a faster way?
> 
> 
> 





Follow-Ups: References: