Archived

This topic is now archived and is closed to further replies.

Bitwise Operations, Memory Addresses, Hex OH MY!

This topic is 6071 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello! As a promise I kept to myself, I am learning how to program video games, which is requiring me to learn c++ since the bulk of the documentation and examples are in c. I am a seasoned VB programmer. In reading the various game programming books, i have stumbled upon bitwise operations, memory addresses, etc, which as a vb programmer, I have been able to avoid. However, I cannot stand not knowing the details of doing certain tasks. My question is the following: How important is it to know bitwise operations, memory addresses, Hex numbers, etc in game programming? If it is something that would be useful, what book or site would you recommend for a beginner? How well do you know these topics? Thanks in advance, Dan

Share this post


Link to post
Share on other sites
All of those topics are great basic skills to have, like any other tools they are only as good as the person that puts them to use. Really any good c++ refrence book will have that sort of info.
One thing about those sort of tools is its easy to understand them and remember them, but knowing when and what to use them for is what experience is from. Like those blindingly fast functions you hear us c++ programmers can create, it uses lots of bit operations in ways that aren''t obvious.
So really, take a tiny bit of time to familarize yourself with them and continue on, and every now and then you''ll realize a good use for them.

Share this post


Link to post
Share on other sites
I would say that they are very important to know. These operations are one of the cornerstones of C/C++ and one of the reasons for its efficiency.

Once you begin to understand these lower level operations, you'll start to understand why certain things are faster than others (and how to avoid them). You'll also develop a better understanding of programming and computers in general, which will really help you in the long run.

I can't think of any books right offhand to recommend, but any good introductory C/C++ book should cover this. Just try to stay away from the "Learn C++ In 27 Minutes -- For People With The IQ of Turtles " type books.

Edited by - I-Shaolin on April 26, 2001 12:27:00 AM

Share this post


Link to post
Share on other sites
I always recommend SAMS books about pretty much anything to do with C/C++. But pretty much any C/C++ book you get is going to cover it (if it doesn''t there should be a no-questions-asked refund as standard warranty on the book )

-Chris Bennett of Dwarfsoft - The future of RPGs Thanks to all the goblins in the GDCorner niche

Share this post


Link to post
Share on other sites
figure out how you could make a 32bit color (ARGB) from four 8bit chars - and the reverse...
That is a good exercise, and useful too ...
I also had problems with pointers - (as most people I guess) - when I started looking at C, but once you get it it is really simple, but it might take a while.
You can also take a look at some simple x86 16bit assembly if you really feel you want to know it all, because you HAVE to learn that stuff in assembly, and it will give you a good feeling about why pointers and bitwise operations exist.

Share this post


Link to post
Share on other sites
Don''t forget about linked lists!!! Personally I feel that one of the biggest reasons that you should have a good understanding of pointers is to make learning/creating/using linked lists, hashes, and queues much easier. I really can''t think of how any dynamic program would function without these data structues. Of course I''m sure you can use someone else''s library (or MFC) to utilize data structures like linked lists.

Best of luck,
~S''Greth

Share this post


Link to post
Share on other sites
Ghhetto:

First of all writing C/C++ is very misleading, if not even wrong. Although C++ has a C subset, proper C++ programming according to it''s idioms and principles avoids lots of C. Stroustrup (the creator of C++) covers lots of the reasons for the inclusion of C into C++ and why he''s unhappy with lots of that heritage in his book "The Design And Evolution of C++". Ergo, you should either be using C or C++, but not C/C++.

Second, although pointers are important in some cases, they are best kept to the lower levels of a system and references preferred everywhere else. They provide the same performance and polymorphism characteristics as pointers while avoiding some of the pitfalls (references can''t be NULL, can''t be bent to another object, are perfectly type-safe...).

Third, there is no magic to hex numbers and bit manipulations. I dunno where to best read up on this stuff, but it''s basic mathematics you should be able to figure out yourself. I''ve learned it at school grade 9 or something... Just remember that the basic concept of a number has nothing to do with it''s underlying representation (base-2, base-16, base-10, fingercounting...).

Fourth, "Accelerated C++" is the single best introductory text on C++. It''s the only one I know of that''s fully recommended by the comp.lang.c++.moderated newsgroup, which pretty much consists of the people who maintain the C++ language... For my review and links to other people''s opinions on the book see my website.

SGreth:
> Of course I''m sure you can use someone else''s library

In fact, you should use the standard C++ libraries! For linked lists use the STL std::list template instead of implementing one yourself. Only exception to this rule is when you really need an intrusive list (one that stores the link pointers in the contained object itself).

JOL:
> figure out how you could make a 32bit color (ARGB) from four 8bit chars

unsigned chars you mean. chars are not guaranteed to be unsigned.

JOL:
>
You can also take a look at some simple x86 16bit assembly if you really feel you want to know it all, because you HAVE to learn that stuff in assembly, and it will give you a good feeling about why pointers and bitwise operations exist.
<

I strongly disagree. You don''t HAVE to learn anything in assembly. In fact, the aforementioned book (accelerated C++) explains pointers and arrays in terms of STL iterators and STL containers... And bit manipulations and hex numbers have nothing to do inherently with assembly.

mafried:
>
Uh.. those operations/concepts make up the heart and core of the C programming language. I have a hard time imagining you being able to do anything without at least a basic understanding of pointers.
<

True for C, not so for C++. Hence I''m emphasizing the fact they are two different languages...

I-Shaolin:
>
Just try to stay away from the "Learn C++ In 27 Minutes -- For People With The IQ of Turtles " type books.
<

100% true. These books are lies in their titles already. Learning C++ is neither easy (...for dummies) nor manageable in "24 hours"...

have fun learning - I did (and do ). To quote Stroustrup (from memory): "C++ is a language designed to make programming more enjoyable for the professional programmer".

BTW, tried to post this yesterday, but got disconnected from the server with a ''too many people are accessing the site'' message... very annoying.

regards,

BuschnicK


Life would be much easier if I had the source code.
blackfish.sourceforge.net

Share this post


Link to post
Share on other sites
to BuschnicK about assembly...
you don''t need to understand anything about assembly to be a good programmer, but it really helped me a lot in the understanding of computer systems in general and bit operations in perticular. There is always some hardware in the end and a understanding of assembly for any hardware is a very good way to understand ALL datatypes since programming always falls back down to that level, and noone can argue about that


ohh... and sorry about the unsigned keyword beeing leftout...

I still argue that knowing assembly is a good thing, not a bad thing.

this is how you can make a 32 bit color from 4 8bit VALUES (chars or whatever)

u_int_32 color( 0xFF<<24 | 0x23<<16 | 0xA3<<8 | 0x3B );
this is now true:
color == 0xFF23A33B;



Share this post


Link to post
Share on other sites