home *** CD-ROM | disk | FTP | other *** search
/ Media Share 13 / mediashare_13.zip / mediashare_13 / ZIPPED / PROGRAM / APR94_1.ZIP / GA.ZIP / SOURCE.ZIP / GRPHUTIL.CPP < prev    next >
C/C++ Source or Header  |  1994-01-10  |  1KB  |  55 lines

  1. //Copyright (C) Man Machine Interfaces 1994. All rights reserved.
  2.  
  3. #include "stdafx.h"
  4. //Headers needed for EOS programs
  5. //You need EOS v1.1 to compile this code
  6. #include "eos.h"
  7. #include "eosutil.h"
  8.  
  9. //graph GA headers
  10. #include "grphutil.h"
  11.  
  12. BYTE AllelesToByte(Allele *pAlleles, int from, int to)
  13. {
  14.     BYTE temp = 0 ;
  15.     BYTE powOf2 = 1 ;
  16.     int count = 0 ;
  17.     for(int i=from; i<=to && count++ < 8;i++) {
  18.         if (pAlleles[i])
  19.             temp += powOf2 ;
  20.         powOf2<<=1 ;
  21.         }
  22.     return temp ;
  23. }
  24.  
  25. uint AllelesToInt(Allele *pAlleles, int from, int to) 
  26. {
  27.     uint temp = 0 ;
  28.     uint powOf2 = 1 ;
  29.     int count = 0 ;
  30.     for(int i=from; i<=to && count++ < 16;i++) {
  31.         if (pAlleles[i])
  32.             temp += powOf2 ;
  33.         powOf2<<=1 ;
  34.         }
  35.     return temp ;
  36. }
  37.  
  38. ulong AllelesToLong(Allele *pAlleles, int from, int to)
  39. {
  40.     ulong temp = 0 ;
  41.     ulong powOf2 = 1 ;
  42.     int count = 0 ;
  43.     for(int i=from; i<=to && count++ < 32;i++) {
  44.         if (pAlleles[i])
  45.             temp += powOf2 ;
  46.         powOf2<<=1 ;
  47.         }
  48.     return temp ;
  49. }
  50.  
  51. int GetNumBitsToEncode(int n)
  52. {
  53.     return Max((int)ceil(log2(n)),1) ;
  54. }
  55.