Re: Joining 2 char to 1 short
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Fri, 30 Jun 2006 17:48:54 GMT
Steffen Loringer <steffen.loringer@xxxxxxxxxx> writes:
Hi,
I'm using the following function to join 2 char (byte) into one short on
a 32 bit X86 platform:
unsigned short joinUnsigShort(unsigned char a,unsigned char b)
{
unsigned short val = 0;
val = a;
val <<= 8;
val |= b;
return val;
}
Will this also work if compiled on a PowerPC? Are there better ways to
do it?
It will do what it says. Whether it will do what you want depends on
exactly what you want, which you haven't quite told us.
There are many possible ways to join two chars into a short. What
exactly are you trying to accomplish? Do you want the value of "a" in
the high-order bits of the result? Do you want it in the leftmost
(lowest address) portion of the result?
--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
.
- References:
- Joining 2 char to 1 short
- From: Steffen Loringer
- Joining 2 char to 1 short
- Prev by Date: Re: So what Standard are we working off?
- Next by Date: Re: Need to implement strdup, strnicmp and stricmp
- Previous by thread: Re: Joining 2 char to 1 short
- Next by thread: void vs void* (philosophical question)
- Index(es):
Relevant Pages
|