LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-03-2013, 04:15 AM   #1
xeon123
Member
 
Registered: Sep 2006
Posts: 374

Rep: Reputation: 16
How a computer knows it's a char and not a number?


A character is represented by an octet (8 bytes), and a computer only works with bits. How the computer knows that a char it's a character and not a number?

Last edited by xeon123; 03-03-2013 at 04:17 AM.
 
Old 03-03-2013, 05:11 AM   #2
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
It's going to help you: See here
 
Old 03-03-2013, 05:12 AM   #3
goumba
Senior Member
 
Registered: Dec 2009
Location: New Jersey, USA
Distribution: Fedora, OpenSUSE, FreeBSD, OpenBSD, macOS (hack). Past: Debian, Arch, RedHat (pre-RHEL).
Posts: 1,335
Blog Entries: 7

Rep: Reputation: 402Reputation: 402Reputation: 402Reputation: 402Reputation: 402
Check out this thread, probably explains it better than I can.

http://stackoverflow.com/questions/5...ry-location-is
 
Old 03-03-2013, 05:58 AM   #4
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
The short answer is that "it doesn't".

The computer is a pretty dumb machine. It's only virtue is that it can do lots (and when we say "lots" we really mean it) of very simple operations with numbers in very short amounts of time.

All the chips know about are numbers (well, not even that, but anyway...). It's up to the applications, programming languages, interpreters and, ultimately, ourselves, to give one or another meaning to the results that the machine shows in one or another form.
 
Old 03-03-2013, 06:32 PM   #5
Soadyheid
Senior Member
 
Registered: Aug 2010
Location: Near Edinburgh, Scotland
Distribution: Cinnamon Mint 20.1 (Laptop) and 20.2 (Desktop)
Posts: 1,672

Rep: Reputation: 486Reputation: 486Reputation: 486Reputation: 486Reputation: 486
Quote:
A character is represented by an octet (8 bytes)
Hmmm... not as I remember it. That should be 8 bits. In ASCII code, the letter "A" is 10000010 (one byte) in binary or 101 in octal (I've still got an old DEC PDP 11 programming card lying about somewhere.) but then, your computer has to know you're using ASCII rather than something else.
Other ASCII codes are here

Last edited by Soadyheid; 03-03-2013 at 06:35 PM.
 
1 members found this post helpful.
Old 03-03-2013, 07:10 PM   #6
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Quote:
Originally Posted by xeon123 View Post
A character is represented by an octet (8 bytes), and a computer only works with bits. How the computer knows that a char it's a character and not a number?
Depends on the font used.

Usually the character is represented by one to six bytes (UTF-8) determined by flag bits.

(reference: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8)

As to the question: How the computer knows that a char is a character and not a number...

It is always a number.

How that number is used is what determines if it is a character or something else.

The following sequence is an illustration:
Code:
...
   char a;
   a = 'A';  /* set a to the the number that represents an upper case A */
   a++;      /* increment the number */
   if (a == 'B') printf("letter B found\n");
...
It is all up to how the number is used.
 
Old 03-03-2013, 07:25 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
At the low level, its 8 Bits = 1 byte in std ASCII in modern systems, aka octet.
The reason for 'octet' is that other systems don't always use 8 bits.
Note that a word size is the basic default size of a sequence of bits used by the computer. Usually a power of 2.
Over time we've had 4, 8, 16, 32 and now 64 bit words.
Note that old mainframe systems sometimes used others sizes eg 36 (note that's a multiple of 2, although not an integer power).
Incidentally, IBM mainframes use a different notation from ASCII, known as EBCDIC.

http://www.asciitable.com/
https://en.wikipedia.org/wiki/ASCII
https://en.wikipedia.org/wiki/EBCDIC

As you'll see, its a matter of convention (aka human rules) as to what a bit pattern represents.

See this https://en.wikipedia.org/wiki/Endianness for a related problem of interpretation of different byte orders .

Its a common qn to ask a student to use a given lang to set up tests to determines what a given pattern represents eg see printf options in C (& used by other langs as well) https://en.wikipedia.org/wiki/Printf_format_string.

Enjoy
 
Old 03-04-2013, 06:37 AM   #8
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Word sizes vary a lot - historically there have been 1 bit computers (ALUs actually, used in old calculators), 12 bit (PDP-8 and PDP-12), 18 bit (PDP-15, and PDP-10 sort of, later 36 bit DecSystem 10). One odd use of the DecSystem 10 was support for variable byte sizes (1 - 36 bits). This was used occasionally for error recovery reading raw data from 9 track tapes (8 data bits + 1 parity). Errors could then be analyzed by software to determine how to correct data above and beyond what the hardware could do (I was doing this to recover data from broken backup tapes).

One of the more extreme general purpose computers was the IBM stretch (http://en.wikipedia.org/wiki/IBM_7030_Stretch) which had support for 1 to 8 bit bytes, 7 bit registers, and up to 64 bit floating point , and even a 128 bit accumulator.

Last edited by jpollard; 03-04-2013 at 06:43 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I get the number of elements in a char*[] in c++? chinho Programming 7 01-28-2011 01:30 AM
how do i write a asci-char withthe number? kalleanka Programming 11 04-28-2008 12:53 PM
Finding computer model number paddyjoy Linux - Newbie 3 02-14-2006 11:47 PM
Computer incorrectly reports number of logged in users phil.d.g Linux - General 5 10-22-2005 04:09 AM
How do I add character+number to get char in C++? needforspeed Programming 10 02-10-2004 12:16 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:01 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration