A couple of memory questions
Hey there, I have a few questions on memory. If anyone could help I''d be grateful.
Say you have a file full of charactors like a text file, this file can be opened in binary format,...yes? And this means that it has been loaded (into variables in the program) as 1''s and 0''s?
If this is true, how many 1''s and 0''s does it take to define a charactor? I read that a single memory location is a byte and each byte contains 8 bits. Is each bit a 1 and a 0 ?
And how many 1''s and 0''s does it take to define an integer?
Thanks for any help
January 08, 2002 10:13 AM
quote:
Original post by AbeE
Hey there, I have a few questions on memory. If anyone could help I''d be grateful.
Say you have a file full of charactors like a text file, this file can be opened in binary format,...yes? And this means that it has been loaded (into variables in the program) as 1''s and 0''s?
If this is true, how many 1''s and 0''s does it take to define a charactor?
A character is usually one byte, so 8 bits per character. Unicode characters are 2 bytes, so those would have 16 bits.
quote:
I read that a single memory location is a byte and each byte contains 8 bits.
Is each bit a 1 and a 0 ?
Yes.
quote:
And how many 1''s and 0''s does it take to define an integer?
Depends on the machine. On a P4, 32. On a 186, 16. On others, even more (or less)
January 08, 2002 10:25 AM
Some mis-information from the other Anonymous poster, so let me try to clarify everything:
First, any file can be opened as Binary. Binary just means it may or may not be a text file. It does not load the file into your program as 1''s and 0''s, the smallest segment of a file you can load is 1 BYTE which equals 8-bits. A bit has 2 states.. on/off (1/0).
The number of 1''s and 0''s it takes to define an integer is variable... depends on what ''you'' consider an integer. Turbo C/C++ defines an integer as 16-bit''s with values ranging from -32,768 to 32,767 (unsigned int is from 0->65535). MS VC++ defines an integer as 32-bit''s (I think it''s range is -2^31 <-> (2^31) -1). Anyways, the # of bits to an integer is variable dependent on the compiler. I beleive the anonymous poster was thinking of the number of bits per CPU register, as opposed to an "integer".
In VB-
Byte = 8bits
Integer = 16bits
Long = 32bits
In VC-
char = 8bits
short = 16bits
int = 32bits
long = 32bits
I hope this clarified some things for you.
Billy - BillyB@mrsnj.com
First, any file can be opened as Binary. Binary just means it may or may not be a text file. It does not load the file into your program as 1''s and 0''s, the smallest segment of a file you can load is 1 BYTE which equals 8-bits. A bit has 2 states.. on/off (1/0).
The number of 1''s and 0''s it takes to define an integer is variable... depends on what ''you'' consider an integer. Turbo C/C++ defines an integer as 16-bit''s with values ranging from -32,768 to 32,767 (unsigned int is from 0->65535). MS VC++ defines an integer as 32-bit''s (I think it''s range is -2^31 <-> (2^31) -1). Anyways, the # of bits to an integer is variable dependent on the compiler. I beleive the anonymous poster was thinking of the number of bits per CPU register, as opposed to an "integer".
In VB-
Byte = 8bits
Integer = 16bits
Long = 32bits
In VC-
char = 8bits
short = 16bits
int = 32bits
long = 32bits
I hope this clarified some things for you.
Billy - BillyB@mrsnj.com
What about capital letters? If I type a capital letter into a text editor is it written as a completely different byte pattern or is it the same pattern but with a kind of identifier before saying its a capital.
How many different charactors are available?, if there is every letter on the keyboard, its capital, the numbers, the sysmbols, is there any way to represent other keys as charactors too like Enter,...TAB etc (though obviously not in a text editor). I don''t even know if that makes any sense, I think I confusing myself !
How many different charactors are available?, if there is every letter on the keyboard, its capital, the numbers, the sysmbols, is there any way to represent other keys as charactors too like Enter,...TAB etc (though obviously not in a text editor). I don''t even know if that makes any sense, I think I confusing myself !
There is a distinction between text and binary files, because not all platforms format text the same way.
For example: on Windows, the end of a line is represented by two characters, '\r' and '\n'. Unix uses just a single char, '\n'. Similarly, some DOS textfiles use ^Z as the end-of-file character, Unix does not.
If you use a file as a binary file, you use the actual chars/bytes it contains. However, if you read/write it as a textfile, the platform-specific differences will be translated automatically, so you can use '\n' as the end of a line on every platform.
btw: do a search for 'ASCII table'
Edited by - kvh on January 8, 2002 12:57:47 PM
For example: on Windows, the end of a line is represented by two characters, '\r' and '\n'. Unix uses just a single char, '\n'. Similarly, some DOS textfiles use ^Z as the end-of-file character, Unix does not.
If you use a file as a binary file, you use the actual chars/bytes it contains. However, if you read/write it as a textfile, the platform-specific differences will be translated automatically, so you can use '\n' as the end of a line on every platform.
btw: do a search for 'ASCII table'
Edited by - kvh on January 8, 2002 12:57:47 PM
January 08, 2002 12:18 PM
quote:
Original post by Anonymous Poster
Some mis-information from the other Anonymous poster, so let me try to clarify everything:
No, not really. Check your facts before posting something like that.
quote:
The number of 1''s and 0''s it takes to define an integer is variable... depends on what ''you'' consider an integer. Turbo C/C++ defines an integer as 16-bit''s with values ranging from -32,768 to 32,767 (unsigned int is from 0->65535). MS VC++ defines an integer as 32-bit''s (I think it''s range is -2^31 <-> (2^31) -1). Anyways, the # of bits to an integer is variable dependent on the compiler. I beleive the anonymous poster was thinking of the number of bits per CPU register, as opposed to an "integer".
The number of bits per CPU register is defined to be the integer size by most compiler developers. Turbo C is for programming 16 bit systems under 16-bit windows. (According to Borland''s home page.) Since x86 processors used to be 16 bit, there is a compatibility mode for doing this so we can all run our old programs on the newer processors. I would suggest that at this point there''s little reason to program in 16-bit x86 unless you''re working on embedded systems with cheap processors like 186''s or 286''s.
If you use Borland''s C++ builder, which is their ''modern'' product, the ints would be 32 bit, as they should be on modern computers.
If you use the dec/alpha Visual C on a 64 bit alpha processor, your integers will be 64 bits.
January 08, 2002 12:26 PM
Actually.... I know my facts, and as i pointed out, you were talking about integers in refrence to register variables. Just because you can name 2 C++ compilers that define an integer as 32-bits doesn''t make it correct. If you check the ANSI C/C++ documentation it states that an integer does not have to be 16/32/64 bits for anything on any platform. a Short = 16 bits, and a long = 32 bits.. and an integer can be either one of the two. An integer in VB6 (which IS a moderm day compiler by Microsoft) defines an Integer (on current platforms) as a 16-bit number.... even though, the Register variables of the CPU are 32-bits... go figure.
Billy
Billy
January 08, 2002 12:37 PM
Anyways, all i was pointing out was that "integer" sizes aren''t always the same depending on the platform/compiler that you''re working with, and it has nothing (well, some, but little) to do with register variables of the CPU.
Billy
Billy
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement