how come i see 256 as the number of bytes in character arrays so often?
is there something magical that happens?Code:char * myChar[256];
how come i see 256 as the number of bytes in character arrays so often?
is there something magical that happens?Code:char * myChar[256];
AOL: GrNxxDaY
IDE: Dev-C++ Beta 5 (v4.9.4.1)
Project: Eye of Sahjz (text-RPG)
If you think I may need help, please IM me.
No. There is nothing magical about 256. 1, 2, 4, 8, 16, 32, 64, 128, 256,...1024, are all powers of 2^x. It is just a practice among programs since we deal with 0s and 1s.
Kuphryn
it's a common size
Generally, a char is 1 byte - 8 bits - 256 possible values.
In games and such it is wise to hold state information about all the possible values (for key presses and things). You can then reference a state based on it's ASCII value.
Did I make enough sense with that?
you only need 1 byte to do that... not 256.
so its just a convention to use char name[256]; ?
AOL: GrNxxDaY
IDE: Dev-C++ Beta 5 (v4.9.4.1)
Project: Eye of Sahjz (text-RPG)
If you think I may need help, please IM me.
No, you would need 256 bits if all you stored was if key was up or down. I've still always seen 256 bytes since it's probably faster to access.
It's best that you keep your data on word boundaries,
some compilers do this automatically.
Knuth gives out $2.56 since 256 pennies is one hexadecimal dollar.
*goes crazy and doesn't understand*
a regular char type has is 1 byte.. .that's 255 or so diff. values it can store. my question is why do people use 256 bytes (not bits!!) so often.
AOL: GrNxxDaY
IDE: Dev-C++ Beta 5 (v4.9.4.1)
Project: Eye of Sahjz (text-RPG)
If you think I may need help, please IM me.
You need to handle multiple keypresses.
Some implementations of malloc are optimized for
powers of 2.
BUFSIZ and the size of a virtual page
are usually powers of 2.
When you subtract a unsigned number by 256 all your
doing is clearing the 8 bit. Doing an and instruction might
be faster on a really old processor. Well you can make your
code more confusing doing it
>>why do people use 256 bytes (not bits!!) so often.
Even though that would be the most size efficient, the smallest standard datatype in C/C++ is a char. There is no single bit variable type, and often times it's more work if you're trying to manipulate bits (and people are generally lazy).
>how come i see 256 as the number of bytes in character arrays so often?
The exact reason why 256 is used to so much is because the programmer chose to use it, probably because they felt it was not too much and not too little. I personally think that 256 is too small for a char array since they are usually used as buffers for input and you never know how much input there is.
-Prelude
My best code is written with the delete key.
i think prelude finally got what i was asking (i'm not good at explaining problems i think). thakns
AOL: GrNxxDaY
IDE: Dev-C++ Beta 5 (v4.9.4.1)
Project: Eye of Sahjz (text-RPG)
If you think I may need help, please IM me.