TIP: Click on subject to list as thread! ANSI
echo: aust_c_here
to: andrew clarke
from: Paul Edwards
date: 1996-06-27 23:01:16
subject: optimisation

ac> void raw_to_mystruct(unsigned char *raw, MYSTRUCT * x)
ac> {
   x->thang = 0L;
   x->thang |= raw[3];
   x->thang <<= 8;
   x->thang |= raw[2];
   x->thang <<= 8;
   x->thang |= raw[1];
   x->thang <<= 8;
   x->thang |= raw[0];
ac> }

ac> Anybody know how to simplify (or more specifically optimise) the code in 
ac> the raw_to_mystruct function?  I was thinking along the lines of

 x->thang = (raw[3] << 8) | (raw[2] << 8) | (raw[1] <<
8) | raw[0];

ac> but am unsure if that's a correct translation.  Thanks. 

No, that is an incorrect translation.  What you want is

(raw[3] << 24) | (raw[2] << 16) | (raw[1] << 8) | raw[0].

I don't know whether it will be faster or not though!  BFN.  Paul. 
@EOT:

---
* Origin: X (3:711/934.9)

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.