home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.mac.programmer
- Path: sparky!uunet!gumby!kzoo!k044477
- From: k044477@hobbes.kzoo.edu (Jamie R. McCarthy)
- Subject: Re: Question about bit manipulation
- Message-ID: <1993Jan24.173648.5148@hobbes.kzoo.edu>
- Organization: Kalamazoo College
- References: <1993Jan24.023728.5051@afterlife.ncsc.mil>
- Date: Sun, 24 Jan 1993 17:36:48 GMT
- Lines: 55
-
- mssmith@afterlife.ncsc.mil (M. Scott Smith) writes:
- >
- >Basically, I write to the screen by doing something like this:
- >long *long_ptr;
- >long_ptr = (address of memory location representing part of screen to draw to)
- >*long_ptr = 0xaaaaaaaa;
- >
- > All works well. I have developed a system for converting pictures into
- >this format, so I can easily (and VERY quickly!) plot these pictures on screen.
-
- OK, if it works well, I won't give you the standard didacticism about
- (1) stripping your addresses, but not the screen's address, (2) calling
- SwapMMUMode(), (3) calling ShieldCursor(), and (4) never assuming that
- the screen's rowBytes is anything other than
- ((**(**theGDevHndl).gdPMap).rowBytes & 0x3FFF).
-
- :-)
-
- >But, now I want to replace all "00"'s with the color from the background at
- >that location.. So, if the first four pixels of the screen look like this:
- >a1a1a1a1
- >And I want to plot a "ee0000ee" on the screen, I would want the result to be:
- >eea1a1ee
- >Now, the way that I'm attacking this, is to basically
- >bit-or the two together.
- >I.e. "ee0000ee | 00a1a100" should yield "eea1a1ee", which is what I want.
-
- Yep, assuming you managed to pull 00A1A100 off the screen OK. If I were
- in a pedantic mood, I'd point out that the most obvious method,
- (*long_ptr) & (~0xEE0000EE), doesn't work; you need to make up a mask,
- each byte of which is either 00 or FF.
-
- >But the problem is, Think C doesn't seem to want to deal with long's greater
- >than four hexadecimal digits.. That is, if I do:
- > printf("%x\n", 0xffffffff);
- >It prints:
- > ffff
-
- This sounds like a printf-related problem. You probably have to use
- "%lx" to print long hex values, or declare your ints to be four-byte, or
- sacrifice a boar to the moon goddess, or something--printf can get
- pretty confusing and I don't claim to understand it.
-
- > unsigned long int junk = 4147483645;
- > printf ("[%ld]\n", junk);
- >It prints out "-147483651"..
-
- Well, that's the signed equivalent of junk. (-147483651 + (2^32) equals
- 4147483645.) Try sticking a "u" somewhere after the "%", or maybe
- chanting "Dalai Lama" while your program compiles.
- --
- Jamie McCarthy Internet: k044477@kzoo.edu AppleLink: j.mccarthy
- "So since You do NOT hold to The Warriors Code,
- it is OBVIOUS that you do NOT have worthwhile Values."
- - drieux
-