Just a question, if I intend people can only get level 255 on some game,if they make it at level 256.I would create dynamically a byte and multiply with the first to get an short int.
If you intend to have people reach a maximum of level 255, then how are they supposed to go past 255?
A float is no different from a integer in this case anyways. "myFloat = myByte1 * myByte2" is fine. You might need to cast one of the integers to a float type which doesn't cost anything and is probably safe cast statically.
I'm not really sure I understand. What's the purpose of the float?
In addition, you'll find that allocating enough data to allow for the maximum amount of levels is more efficient than trying to allocate memory dynamically when it's needed, especially in cases like this. You're better off just using a short or long.
I think I understand what OP is asking.
If you initially have a single byte A to store a number and you need to increase the capacity, you can do this by adding another byte B. Then the actual number is B*256+A. This is called "fixed point arithmetic" because each bit or group of bits represents a specific magnitude (A's magnitude is 1 and B's is 256). It's not possible to do something analog to this for float because float uses floating point arithmetic; that is, the bits represent a variable magnitude depending on an exponent.
Why is everyone so dead set on multiplying unsigned characters together? I'm with Disch, use an unsigned int. There is no need to do any math or anything like that, you're just wasting time and effort for something that is inbuilt.
I should also note that using smaller data types is not necessarily "more optimized". It might actually be faster to use an int than it would be to use a char for a variable. Especially if you're doing what you're doing and casting to/from larger types whenever your add/multiply/whatever.
Also, depending on the context of how the char is used, it might not even use any less memory than an int (the char might be padded to the next 4-byte boundary, for example).
Really, don't worry about this kind of micro-optimizing crap. Even if my some chance it does make some kind of performance improvement, it would be so small that nobody would ever notice.
Use types that are large enough for what you want.
Disch You are correct. Depending of what type of controller used 8, 16, 32 or 64bit buswidth in some cases 128bit will depend on speed and optimize the code will be. In a regular PC always use int (long int) which take use of the structure of the controller. Why ever use char???? Char's are for high speed 8bit microcontroller. Forgot to say. Most compilers for C++ in the PC world turn int's into long int (32bits) to take advance of the computer structure.