Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm not sure if this is an appropiate question to be posting on this site. It's not a Linux specific question but since I use Linux I thought it would be okay.
I'm reading up on ASCII and was wondering if someone would be able to tell me if I have it right. I'm not sure if I'm 100% correct but this is what I've picked up so far:
A file is stored as a long list of bytes.
A byte has 256 combinations
A single byte represents any one of the 256 characters
Each character is a byte, so:
"A" 01000001 is a byte
"?" 00111111 is a byte
"3" 00000011 is a byte
A file name can be up to 256 characters, so that means up to 256 bytes.
If a file contained only one word like "Hello" then the size of that file would be 5 bytes.
If I'm right about what I've learned so far, I guess what I would like to know is where do Decimal, Hexidecimal and Octal numbers come into the picture?
Sorry if this is obvious but I'm just starting to learn both Linux and computers and would like to have a clear understanding of how this works.
AIUI, the octal, decimal and hexadecimal entries are simply alternate ways to represent the byte sequences in more human-accessible forms. Depending on the programming environment, one base can be more convenient to use than another, otherwise they are all equivalent. The wikipedia entry on hexadecimal explains it like this:
Quote:
Each hexadecimal digit represents four binary digits (bits) (also called a "nibble"), and the primary use of hexadecimal notation is as a human-friendly representation of binary coded values in computing and digital electronics. For example, byte values can range from 0 to 255 (decimal) but may be more conveniently represented as two hexadecimal digits in the range 00 through FF. Hexadecimal is also commonly used to represent computer memory addresses.
It's fairly easy to convert byte sequences between binary, octal, and hexidecimal bases, which is why they're all commonly used in programming. But converting to and from decimal is a bit trickier, and it's mostly used when something needs to be human-readable.
Last edited by David the H.; 04-27-2010 at 11:19 PM.
Reason: small word change for accuracy
As you learn things, keep focussed on the groupings of definitions. For example, these are all names for number systems:
binary
octal
decimal
hexadecimal
None of these has anything to do with the definitions of
bit
nibble
byte
And neither group has anything to do with:
ascii
unicode
ebcdic
and other character encoding schemes
To take one cut thru this, let's first define a "byte" by its number of bits:
1000 in binary
10 in octal
8 in decimal or hex
but it's **meaning** may be different in ascii, unicode, or ebcdic
So there are at least 3 ways to define something:
What is it?
How is it measured?
What does it do?
binary, hex, etc. are just ways of representing numbers. Remember, it's still the same value, just represented in a different way.
bit, byte, etc. have to do with the way computers store numbers (computers use binary):
a "bit" is a binary digit, a 1 or 0.
a "byte" is an 8-bit binary number. A lot of the computer's design is byte-centric. The RAM is basically an array of byte-size storage cells. Your hard drive stored data in units of bytes. Your CPU's word size is a multipla of 8, to make it easier to process bytes.
A file name can be up to 256 characters, so that means up to 256 bytes.
If a file contained only one word like "Hello" then the size of that file would be 5 bytes.
If I'm right about what I've learned so far, I guess what I would like to know is where do Decimal, Hexidecimal and Octal numbers come into the picture?
Sorry if this is obvious but I'm just starting to learn both Linux and computers and would like to have a clear understanding of how this works.
Thank You.
Yes, try:
Code:
bash-3.1$ printf Hello > te
bash-3.1$ stat -c %s te
5
5 bytes in size, if you add a newline it will be 6.
Okay I can now see how using hex is easier than dealing directly with binary. So in what situation would you be writing or reading hex? Are there specific files that have to be written in hex?
No I'm sorry I don't understand. I thought that hardware can only understand binary or "sequences of on's and off's", and since files are stored in hardware it would have to be in binary?
Do you mean that files are not "stored in binary" in the way that binary is just a human interpretation of the on and off sequences.
Last edited by Ronin-8; 04-28-2010 at 06:14 PM.
Reason: Thought about it some more, lol.
files are not stored in hex--or binary (But-see the discussion to follow)--or decimal---or octal. Those are all number systems.
Digital storage is in bits. We have seen some definitions here, and you can look it up also. A "bit" is a way of describing an element which can have two states. To be sure, the word "binary" is sometimes used in reference to this 2-state paradigm. Personally, I think it is better to make the distinction between: Analog data: stored or transmitted as a continuum of voltage or current states Digital data: stored or transmitted as a series of bits (or bytes, where 1 byte = 8 bits)
Technically files are stored in binary, but that is intrinsic to the file system. It is transparent to the user. It's impossible to have "a file in hex" or "a file in decimal".
Imagine a file as an array of numbers, each of which can be an integer from 0 to 255 (inclusive).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.