TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: CHRISTOPHER BUTLER
from: CLIFF RHODES
date: 1997-04-08 21:02:00
subject: bytes :)

--> Christopher Butler wrote to All  <--
CB>If I've got two variables, stored as arrays of 3 bytes:
CB> 
CB>typedef byte DateType[3];
CB> 
CB>How do I test whether one is greater than the other?
Assuming the bytes are in order [0] being the most significant, and
each byte represents a number:
int DTcmp(const DateType *a, const DateType *b)
{
  /* Returns:
   *   1 if *a > *b
   *   0 if *a == *b
   *  -1 if *a < *b
   */
  int  i;
  char *x = (char *) a;
  char *y = (char *) b;
  for(i = 0; i < sizeof(DateType); i++, x++, y++)
  {
     if(*x > *y)  return 1;
     if(*x < *y)  return -1;
  }
  return 0;
}
PS: Why isn't this a class instead of a type?
X CMPQwk 1.42 1692 X"In headaches and in worry Vaguely life leaks away." - 
W.H. Auden
--- Maximus/2 3.01
---------------
* Origin: COMM Port OS/2 juge.com 204.89.247.1 (281) 980-9671 (1:106/2000)

SOURCE: echomail via exec-pc

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™.