delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/11/14/11:57:11

Message-ID: <346C8264.4C58AAA1@lausd.k12.ca.us>
Date: Fri, 14 Nov 1997 08:55:00 -0800
From: csantill <csantill AT lausd DOT k12 DOT ca DOT us>
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: QUAD_WORD (unsigned long long) bit testing

from: csantill AT lausd DOT k12 DOT ca DOT us

Is it possible to do bit testing on the DJGPP data type "long long"?
It doesn't seem to work the standard way of bits like this(this is for
longs):
unsigned char Is_Bit_Set(long foo, char bit)
{
  const constant = 0x80000000;
  // Must be 0x80*((sizeof(foo)-1)*16); would be 0x8000000000000000
  // or 0x80*((8-1)*16) but RHIDE says the constant is too big

  return ( ( (constant) & ( foo << bit ) ) > 0);
}

Would I have to create a struct to define QUAD_WORD like this one so
I could bit check through out the the LONG LONG:
typedef struct
{
  unsigned long high, low;
  unsigned long number;
}QUAD_WORD;
then write a func to test the bits like so(will return -1 for error
but that is fairly impossible):
char Is_Long_Long_Bit_Set(QUAD_WORD qw,unsigned char bit)
{
  unsigned long _high=qw.high, _low=qw.low;

  if((bit%64) > 16)
    {return ( ( (0x80000000) & ( _high << bit ) ) > 0);}
  else
    {return ( ( (0x80000000) & ( _low << bit ) ) > 0);}

  return -1;
}

Would all stuff I did be correct to do bit test w/ a struct for Long
Long?

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019