| | |
bitmapped grahics help
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Aug 2008
Posts: 91
Reputation:
Solved Threads: 0
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.
"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.
| 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.
>> 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
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Make love, no war. Cave ab homine unius libri.
Danny
•
•
Join Date: Jun 2007
Posts: 275
Reputation:
Solved Threads: 45
•
•
•
•
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?]
Calculate 16 x 16 bits = (2 x 8) x 16 bits = 256 bits.
•
•
Join Date: Aug 2008
Posts: 91
Reputation:
Solved Threads: 0
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
thank you for your help
•
•
Join Date: Aug 2008
Posts: 91
Reputation:
Solved Threads: 0
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++.
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.
![]() |
Other Threads in the C++ Forum
- Previous Thread: cannot convert `int*' to `int**'
- Next Thread: no-inheritance question
| Thread Tools | Search this Thread |
api array based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






