Question pertaining to limits...

This is a discussion on Question pertaining to limits... within the C++ Programming forums, part of the General Programming Boards category; This is kind of an odd question, but me and a friend are learning C++ together to program a game. ...

  1. #1
    Registered User
    Join Date
    Mar 2005
    Location
    Hampshire, England
    Posts
    8

    Question pertaining to limits...

    This is kind of an odd question, but me and a friend are learning C++ together to program a game. Today he said to me he was slightly worried that a lot of things have a limit of 255 such as number of objects/images. I dont quite believe him and thought I would ask here...

    Is there a limit to images, sounds or anything and is that limit 255?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,830
    Nope.

    Though eventually you'll run out of memory or processing power, so it's generally a good idea to limit the numbers of objects within your program to what it can comfortably manage.

    Programmers often choose their limits on powers of two for some reason
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    People Love Me
    Join Date
    Jan 2003
    Posts
    412
    255 (or 256) is a pretty popular number with anything regarding 8-bit(one byte) stuff.

    If you don't understand why that is, you should learn how to read binary code to better understand how bits and bytes work.

  4. #4
    People Love Me
    Join Date
    Jan 2003
    Posts
    412
    A little snippet from my 70-page tutorial about programming games: a lovely primer on binary digits. I lost a lot of the formatting and such, so it's not as pretty.

    Computers only translate the presence of electricity in their circuits. The presence of an electric current in a circuit is represented by a 1, and the absence of electricity is represented with a 0. Since computers can only translate two different states, they use base 2 counting system to count and represent numbers and information.

    We people use base 10 to count (probably because we have 10 fingers). We have 10 digits we use to count: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. In base two, there is only 0 and 1. Hereís how counting in our base 10 system works. We have a 1ís place, a 10ís place, and so on, going up and up in powers of 10s.

    10^0 = 1 //One's place
    10^1 = 10 //Ten's place
    10^2 = 100 //Hundred's place


    So if we have the number 5402, we have 5 thousands, 4 hundreds, 0 tens, and 2 ones. Now letís try this with base 2. ItĎs like base 10, only it works in powers of 2. Naturally, it will take a lot more digits to represent values than base 10 representations would because the powers of 2 are much smaller than the powers of 10.

    Hereís the table of how binary digits work:

    2^0 = 1
    2^1 = 2
    2^2 = 4
    2^3 = 8
    2^4 = 16
    2^5 = 32
    2^6 = 64
    2^7 = 128
    //All these numbers added together is 255.

    Remember that any number to the 0th power is 1! This is important to remember. The first place at the right will ALWAYS be the 1ís place, and youíll work to the left in powers of the base youíre using from there.

    This might clarify why any number to the 0th power is 1.

    2^3 = 8
    2^2 = 4
    2^1 = 2
    2^0 = 1
    2^-1 = 1/2
    2^-2 = 1/4
    2^-3 = 1/8


    As you work from the right side of the table to the left, you see that the values of the powers are always being divided by two. 8/2 = 4. 4/2 = 2. And so, 2/2 = 1. 1 divided by two is 1/2, and divide that by two again, and you get 1/4.

    Letís try converting the number 170 to binary code. To do this, we start from the left side of the table, to the right. We find the greatest number that will go into 170 ONCE and only ONCE. 128 can go into 170 once, so we place a 1 for our first digit. We then take the remainder, which is 42, and move it to the next column. Does 64 go into 42? No. So we place a 0 in that column. Letís move on and try 32. 32 can go into 42, so we can place a 1 there, which leaves us only 10. Moving on, 16 cannot go into 10 so a 0 is placed there. 8 goes into 10, and we place a 1 there, leaving us with only 2 for the twos column.

    Our resulting number is 1010 1010

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 03:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 06:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 01:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 10:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM

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