unsigne char[] Misunderstood.

This is a discussion on unsigne char[] Misunderstood. within the C++ Programming forums, part of the General Programming Boards category; Hey all, I've been doing some work with OpenGL and have come across something I don't understand, I'm all self-taught ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    102

    unsigne char[] Misunderstood.

    Hey all, I've been doing some work with OpenGL and have come across something I don't understand, I'm all self-taught so I apologize if it is an easy fix. Anyway here's the code
    Code:
    unsigned char bitmapX[] = {
                        0x80, 0x01,
                        0x40, 0x02,
                        0x20, 0x04,
                        0x10, 0x08,
                        0x08, 0x10,
                        0x04, 0x20,
                        0x02, 0x40,
                        0x01, 0x80,
                        0x01, 0x80,
                        0x02, 0x40,
                        0x04, 0x20,
                        0x08, 0x10,
                        0x10, 0x08,
                        0x20, 0x04,
                        0x40, 0x02,
                        0x80, 0x01,
    };
    It supposedly creates an X, however I don't understand what exactly
    0x08 represents or any of them, can anyone explain this concept to me?

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Code:
    unsigned char bitmapX[] = {
        0x80, 0x01, /* 10000000 00000001  #....... .......#*/
        0x40, 0x02, /* 01000000 00000010  .#...... ......#.*/
        0x20, 0x04, /* 00100000 00000100  ..#..... .....#..*/
        0x10, 0x08, /* 00010000 00001000  ...#.... ....#...*/
        0x08, 0x10, /* 00001000 00010000  ....#... ...#....*/
        0x04, 0x20, /* 00000100 00100000  .....#.. ..#.....*/
        0x02, 0x40, /* 00000010 01000000  ......#. .#......*/
        0x01, 0x80, /* 00000001 10000000  .......# #.......*/
        0x01, 0x80, /* 00000001 10000000  .......# #.......*/
        0x02, 0x40, /* 00000010 01000000  ......#. .#......*/
        0x04, 0x20, /* 00000100 00100000  .....#.. ..#.....*/
        0x08, 0x10, /* 00001000 00010000  ....#... ...#....*/
        0x10, 0x08, /* 00010000 00001000  ...#.... ....#...*/
        0x20, 0x04, /* 00100000 00000100  ..#..... .....#..*/
        0x40, 0x02, /* 01000000 00000010  .#...... ......#.*/
        0x80, 0x01, /* 10000000 00000001  #....... .......#*/
    };
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    102
    Well I can see that it creates an X, however I can't find the pattern to use myself is there some way to explain how 0x80 marks the first position? It details the X in my book, it just doesn't explain the numbers and how they correspond to the positions.

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,340
    They are just hex numbers indicating numbers that make a picture when you look at them in binary. Do you know binary and hexadecimal notations? If not, start there. 0x80 is a hexadecimal number that is 128 in decimal and 10000000 in binary.

  5. #5
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    In the real world you won't have to identify a bitmap image by using all hexidecimals nor would you know how to illustrate them yourself. That's just showing you how image data is represented for a black and white bitmap image. Later on you'll encounter bitmap and other images where one whole byte, rather than one bit, represents the red, green and blue properties of one pixel.

  6. #6
    Registered User
    Join Date
    Apr 2007
    Posts
    102
    Well I'm familiar with Binary, but never heard of hexadecimal notations or any thing of that sort, so thanks ill look it up

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. question regarding char *argv[]
    By cnb in forum C Programming
    Replies: 6
    Last Post: 10-08-2008, 04:50 AM
  2. Char[] of C# to what in C++
    By Arkanos in forum C++ Programming
    Replies: 3
    Last Post: 02-13-2006, 07:10 AM
  3. files size to char[]
    By purefan in forum C++ Programming
    Replies: 1
    Last Post: 04-03-2005, 08:43 PM
  4. Replies: 18
    Last Post: 06-21-2003, 10:57 AM
  5. int main(int argc, char *argv[]) ?
    By Shadow12345 in forum C++ Programming
    Replies: 6
    Last Post: 04-22-2002, 04:50 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21