|
getr() & makecol() |
Derezo
Member #1,666
April 2001
|
I'm wondering on how getr(), getb(), etc. work.. What I'm trying to do, is store 4 values inside of one long integer - like makecol() does. The values are going to be width, height, x and y values.. I was thinking of just using makecol() as a way to do it.. but.. I don't know what excess stuff goes on in makecol() and getr(), etc. and don't want it to cause slow down.. because my engine is slow enough Anyhoo, thanks. "He who controls the stuffing controls the Universe" |
DanielH
Member #934
January 2001
|
Well if that is how you want to do it then you need to learn some shifting. I don't know how it would be better to do it. example: int make_val(width,height) If you want one variable to house x,y,width,height than your variable will need 40bits. You could do it. int is only 32 bits. use long. long has 64 bits. |
Derezo
Member #1,666
April 2001
|
Wow, I understand now.. "He who controls the stuffing controls the Universe" |
DanielH
Member #934
January 2001
|
binary isn't that hard to understand. Its just a bunch of 1's and 0' |
Bob
Free Market Evangelist
September 2000
|
quote: This leaves 2 bits for the width? And also, the operator precedence is wrong. The code should really be: This leaves 8 bits for each quantity, so the range is 0-255 for each. Supporting negative numbers will require a bit more work though. -- |
Derezo
Member #1,666
April 2001
|
The problem I have with binary, is that I can't compute it quickly.. "He who controls the stuffing controls the Universe" |
Derezo
Member #1,666
April 2001
|
Bob: "He who controls the stuffing controls the Universe" |
Bob
Free Market Evangelist
September 2000
|
Under I32LP32 compilers (all of them for the x86, save for the special AMD one), long is 32 bits wide. long long (or int64_t or __int64) is 64 bits wide. -- |
DanielH
Member #934
January 2001
|
Bob: Never actually did that before so didn't know the operator precedence. 2^10 ===== 1024=10000000000 // incorrect |
Bob
Free Market Evangelist
September 2000
|
quote:char, unsigned char, signed char 1 byte 8 bits -- |
DanielH
Member #934
January 2001
|
I have "Teach yourself C++ in 21 days" and it has a program to find out the computer/compiler byts amounts for variables. |
Bob
Free Market Evangelist
September 2000
|
DanielH: I have K&R C - the One True C reference. -- |
Derezo
Member #1,666
April 2001
|
I think that in the end, this way will be easier. Of course, I gotta go through learning how to do it.. but it will be easier to have 1 array, than 4 arrays of the same size.. It's going to be used with buttons and menus. I think it's a good way to do it when I compare it to how I did it previously.. with 4 different arrays Thanks a LOT for showing me how to do this guys. "He who controls the stuffing controls the Universe" |
Gabhonga
Member #1,247
February 2001
|
yeah, in case of computer programming you must make binary (and hex...) math/magic your friend...it can help out a lot in simplifying things. -------------------------------------------------------- |
DanielH
Member #934
January 2001
|
Bob- You didn't seem to understand what I was saying. I totally agree with you. You said that machines are different and I was just saying you could find out the sizeof the variables for your machine. Wouldn't this work? I didn't say it would be the same for all machines. I'm talking about that machine and not any other. |
Peter Hull
Member #1,136
March 2001
|
I think the C standard says something unhelpful like short is not longer than int, and int is not longer than long. My microwave was a Microsoft one; it crashed when I put more than one thing at once in it. To be somewhat more useful - in these days it's not usual to be so short of memory that you have to resort to such tricks. One thing that C provides is a bitfield data type. I've never used it but it could be the thing you're after. Pete
|
Bob
Free Market Evangelist
September 2000
|
DanielH: ah, well my appolgies then. -- |
23yrold3yrold
Member #1,134
March 2001
|
If you're using limits.h and C++, you can get the maximum values of the different types on different systems. The ones DanielH posted are all the minimum sizes of those types except int, which is 2 bytes or greater depending on the system. Say, you can get the maximum value of an int like this: int main() -- |
|