943,822 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 891
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Nov 9th, 2008
0

bitmapped grahics help

Expand Post »
I am doing an online course and for one of the chapters (in Practical C++ Programming by Steve Oualline) it had a bitmapped graphics section-only 4 pages long. The chapter is about bit operations and includes a section about hexadecimals. I understoodit until I got to this passage in bitmapped graphics:

"Suppose we have a small graphics devicce- a 16 by 16 pixel monochrome display. We want to set a bit at 4,7. But we have a problem. There is no data type for an array of bits in C++. The closest we can come is an array of bytes. Our 16 by 16 array of bits now becomes a 2 by 16 array of bytes. [Why isn't it a 2 by 2 array?] To set the pixel at bit number 4,7 we need to set the fourth bit of byte (0,7). To set this bit we would use the statement bit_array[0][7] |= (0x80>>(4));"

What was the |= in the statement and I am also in need of a step by step explanation of the bit_array[0][7] |= (0x80>>(4)); statement (dont tell me it was explained above-it didnt make sense to me). Also, how would you output a simple 8 bit by 8 bit graphics that has 1 pixel turned on the rest off(because the book has no explanation of how to output that to the console)?
Thank You for your help.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
CPPRULZ is offline Offline
91 posts
since Aug 2008
Nov 9th, 2008
0

Re: bitmapped grahics help

| is the bitwise OR operator it means you are performing an OR on 1 bit(0 and 1). This is in contrast with the logical OR operator || which performs his actions on true and false values(booleans)

>> is a bitwise right shift operator.
In your case the hex value 0x80 gets shifted 4 bit-positions to the right.

Hope this helps.
Last edited by ddanbe; Nov 9th, 2008 at 6:45 am. Reason: typo
Reputation Points: 2035
Solved Threads: 644
Senior Poster
ddanbe is offline Offline
3,738 posts
since Oct 2008
Nov 9th, 2008
0

Re: bitmapped grahics help

Click to Expand / Collapse  Quote originally posted by CPPRULZ ...
Our 16 by 16 array of bits now becomes a 2 by 16 array of bytes. [Why isn't it a 2 by 2 array?]
A byte is made up of 8 bits. Therefore a row can contain the 16 bits in 2 bytes. There are 16 rows, hence 2 x 16 bytes.

Calculate 16 x 16 bits = (2 x 8) x 16 bits = 256 bits.
Reputation Points: 85
Solved Threads: 45
Posting Whiz in Training
dougy83 is offline Offline
275 posts
since Jun 2007
Nov 9th, 2008
0

Re: bitmapped grahics help

Still how would you output the bitmap? And why is there an = sign after the |?
Last edited by CPPRULZ; Nov 9th, 2008 at 3:21 pm.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
CPPRULZ is offline Offline
91 posts
since Aug 2008
Nov 9th, 2008
1

Re: bitmapped grahics help

a |= b; is the same as a = a | b; It is a sort of shorthand notation. Just as a += b; is the same as a = a + b; It is probably invented to make life of newbies a little harder...
Reputation Points: 2035
Solved Threads: 644
Senior Poster
ddanbe is offline Offline
3,738 posts
since Oct 2008
Nov 9th, 2008
0

Re: bitmapped grahics help

Oh, wow....I don't know how i didn't see that. Still, how would you output the bitmap and why is the book using hexadecimals-is it really neccessary (can you use just binary)?
Last edited by CPPRULZ; Nov 9th, 2008 at 3:58 pm.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
CPPRULZ is offline Offline
91 posts
since Aug 2008
Nov 9th, 2008
0

Re: bitmapped grahics help

Well... hexadecimal is a shorthand for binary, but a very usefull one!
Google hexadecimal to find out more!
Reputation Points: 2035
Solved Threads: 644
Senior Poster
ddanbe is offline Offline
3,738 posts
since Oct 2008
Nov 9th, 2008
0

Re: bitmapped grahics help

I did and I found an article at http://www.codeproject.com/KB/cpp/bitbashing.aspx that explained how a hexadecimal is like a nibble and very useful in representng binary but would it be possible to say bit_array[0][4]=bin 0001 or something like that and do you know of any sites that explain outputing "manual" bitmaps (not pictures)?

thank you for your help
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
CPPRULZ is offline Offline
91 posts
since Aug 2008
Nov 9th, 2008
0

Re: bitmapped grahics help

What do you mean by "manual" bitmaps?
Do you mean to output zeros and ones instead of pixels?
Reputation Points: 2035
Solved Threads: 644
Senior Poster
ddanbe is offline Offline
3,738 posts
since Oct 2008
Nov 9th, 2008
0

Re: bitmapped grahics help

Usually when I google bitmaps I get how to upload .bmp's but I want to manualy set the pixels in say a 16by16 bit bitmap (3,6)=1 (2,9)=1...
I looked at the sample program in teh book and it just outputs "." do you know if you could actually make a bitmap in C++.
Last edited by CPPRULZ; Nov 9th, 2008 at 5:04 pm.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
CPPRULZ is offline Offline
91 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: cannot convert `int*' to `int**'
Next Thread in C++ Forum Timeline: no-inheritance question





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC