473,385 Members | 1,324 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Looking for a C textbook with emphasis on data types

I am supposed to teach an introductory C course with an unusual slant,
and have trouble finding an appropriate textbook. The course will begin
traditionally enough with variables, loops, conditionals, structures,
pointers and fopen/fclose. Beyond that, however, every course and
textbook I had seen is heavy on data *structures*, and touches on other
topics lightly if at all. Whereas I need to stress data *types*,
converting them one into the other, and bit manipulation. By the end of
the course I do not care if my students know what a linked list is, let
alone a binary tree, but they must have good understanding of ASCII,
binary and hexadecimal. For example, it must clear to them why number
353 is actually stored as 0x01 0x61 if it's and INT, but 0x33 0x35 0x33
if it's a CHAR*. Or why converting a numeric CHAR into an INT involves
subtracting 48 -- and not 30, as previous example might suggest.

Is there a textbook with such emphasis on data types, bits, and
hexadecimal, or am I doomed to writing my own?

Jul 14 '06 #1
20 1800
il***@rcn.com said:

<snip>
By the end of
the course I do not care if my students know what a linked list is, let
alone a binary tree, but they must have good understanding of ASCII,
Why? That has nothing to do with C.
binary and hexadecimal. For example, it must clear to them why number
353 is actually stored as 0x01 0x61 if it's and INT,
There is no INT type in C. 353 might be stored as 0x0161, but it might be
stored as 0x6101, 0x00006101 (i.e. in 4 octets), or as 0x61010000 (little
endian, four octets to the int), or in any of a zillion other ways.
but 0x33 0x35 0x33 if it's a CHAR*.
C has no CHAR type. To store the characters '3', '5', and '3', you need
three bytes of storage. A pointer to the first of these characters will
/not/ have the value 0x333533 (unless by some astounding coincidence).
Or why converting a numeric CHAR into an INT involves
subtracting 48 --
It doesn't. If you mean turning '4' into 4 or '6' into 6, it involves
subtracting '0', not 48.
and not 30, as previous example might suggest.

Is there a textbook with such emphasis on data types, bits, and
hexadecimal, or am I doomed to writing my own?
Oh my word. Please, please, please don't write your own, until you
understand what you're talking about.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Jul 14 '06 #2

il***@rcn.com wrote:
I am supposed to teach an introductory C course with an unusual slant,
and have trouble finding an appropriate textbook. The course will begin
traditionally enough with variables, loops, conditionals, structures,
pointers and fopen/fclose. Beyond that, however, every course and
textbook I had seen is heavy on data *structures*, and touches on other
topics lightly if at all.
Are you talking about any C book or some data structures book ?
>Whereas I need to stress data *types*,
Is it required ?
converting them one into the other, and bit manipulation. By the end of
the course I do not care if my students know what a linked list is, let
alone a binary tree, but they must have good understanding of ASCII,
binary and hexadecimal.
Which of these is 'C' ?
>For example, it must clear to them why number
353 is actually stored as 0x01 0x61 if it's and INT,
Is it ?? its NEWS. What if you are using a machine with little endian
byte ordering ?
>but 0x33 0x35 0x33
if it's a CHAR*.
How can number 353 be char * ??
>Or why converting a numeric CHAR into an INT involves
subtracting 48 -- and not 30, as previous example might suggest.
Who told you to subtract 30 ?
You have to subtract ' 0'. And you would have missed ' 0x' while you
were reading.
It should have been 0x30.
Is there a textbook with such emphasis on data types, bits, and
hexadecimal, or am I doomed to writing my own?
Ooops...
No please,,, for god's sake.

Go and read " the holy book" , The C programming language, by K & R.

Jul 14 '06 #3
"arun" writes:
>Is there a textbook with such emphasis on data types, bits, and
hexadecimal, or am I doomed to writing my own?

Ooops...
No please,,, for god's sake.
Think of the children!!!
Jul 14 '06 #4
but 0x33 0x35 0x33
if it's a CHAR*.

How can number 353 be char * ??
If it's a character string "353"

Jul 14 '06 #5
Or why converting a numeric CHAR into an INT involves
subtracting 48 -- and not 30, as previous example might suggest.

Who told you to subtract 30 ?
You have to subtract ' 0'.
48 is decimal value of '0'. In hexadecimal it is 0x30
And you would have missed ' 0x' while you
were reading.
It should have been 0x30.
I know that. I was bringing up an example of a mistake someone
unfamiliar with hexadecimal may make.

Jul 14 '06 #6
il***@rcn.com said:
>
>but 0x33 0x35 0x33
if it's a CHAR*.

How can number 353 be char * ??

If it's a character string "353"
Then it isn't a CHAR *. It's a string literal - a static array of four char.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Jul 14 '06 #7
il***@rcn.com said:
>
>Or why converting a numeric CHAR into an INT involves
subtracting 48 -- and not 30, as previous example might suggest.

Who told you to subtract 30 ?
You have to subtract ' 0'.

48 is decimal value of '0'.
The C Standard does not guarantee this, and it is certainly not true on some
systems where C is used.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Jul 14 '06 #8
On 2006-07-14, il***@rcn.com <il***@rcn.comwrote:
>
>Or why converting a numeric CHAR into an INT involves
subtracting 48 -- and not 30, as previous example might suggest.

Who told you to subtract 30 ?
You have to subtract ' 0'.

48 is decimal value of '0'. In hexadecimal it is 0x30
The size of a monitor is 17 inches. In hexadecimal it is 0x11.
Weird how it looks to others when you assume that everyone is using your
environment, huh.
>And you would have missed ' 0x' while you
were reading.
It should have been 0x30.

I know that. I was bringing up an example of a mistake someone
unfamiliar with hexadecimal may make.
If you are so unfamiliar with hexadecimal that you don't know what 0x
means, you shouldn't be learning programming languages, and if your
students do not know what 0x means, you shouldn't teach them anything
else before that.

--
Andrew Poelstra <http://www.wpsoftware.net/projects/>
To email me, use "apoelstra" at the above domain.
"You people hate mathematics." -- James Harris
Jul 14 '06 #9
il***@rcn.com wrote:
>Or why converting a numeric CHAR into an INT involves
subtracting 48 -- and not 30, as previous example might suggest.
Who told you to subtract 30 ?
You have to subtract ' 0'.

48 is decimal value of '0'. In hexadecimal it is 0x30
Oddly enough, the hexadecimal value of '0' on every one of my systems
is F0.

I guess I should enroll in your class so I can learn C properly.

(gosh, subtracting 48, wow, I am so glad my boss never gave me that
assignment because I foolishly would have subtracted 240. Maybe that's
why I was never given the assignment to convert a numeric CHAR into an
INT.)

Jul 14 '06 #10
<il***@rcn.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
>I am supposed to teach an introductory C course with an unusual slant,
and have trouble finding an appropriate textbook. The course will begin
traditionally enough with variables, loops, conditionals, structures,
pointers and fopen/fclose. Beyond that, however, every course and
textbook I had seen is heavy on data *structures*, and touches on other
topics lightly if at all. Whereas I need to stress data *types*,
converting them one into the other, and bit manipulation. By the end of
the course I do not care if my students know what a linked list is, let
alone a binary tree, but they must have good understanding of ASCII,
binary and hexadecimal. For example, it must clear to them why number
353 is actually stored as 0x01 0x61 if it's and INT, but 0x33 0x35 0x33
if it's a CHAR*. Or why converting a numeric CHAR into an INT involves
subtracting 48 -- and not 30, as previous example might suggest.

Is there a textbook with such emphasis on data types, bits, and
hexadecimal, or am I doomed to writing my own?
The reference document you seek is called:
"INTERNATIONAL STANDARD ŠISO/IEC ISO/IEC 9899:1999 (E)
Programming languages - C"

and it costs $30 or so in PDF format. Its fairly expensive in printed form,
but you can probably run off a copy at Kinkos for a moderate price.

The section you are interested in is:
6. Language

With special ephasis on 6.5 Expressons and 6.7 Declarations

I should mention that most of your comments above are utter nonsense.

Things like ASCII/EBCDIC and big/little endian issues can easily be made
language neutral if you know what you are doing.

Additional reading:
_The C Programming Language_, by Kernighan and Ritchie, 2nd Edition
_C Programming FAQs: Frequently Asked Questions_, by Steve Summit

There is a book that is a bit of overkill for what you are trying to cover,
but which may prove helpful in developing your course outline.

_C Unleashed_ by Richard Heathfield, Lawrence Kirby has a chapter (5)
called "Playing with Bits and Bytes" which should be useful for developing
your course outline.
Jul 14 '06 #11
Andrew Poelstra <ap*******@nowhereat.allwrites:
[...]
If you are so unfamiliar with hexadecimal that you don't know what 0x
means, you shouldn't be learning programming languages, and if your
students do not know what 0x means, you shouldn't teach them anything
else before that.
The use of a 0x prefix to denote hexadecimal is just syntax, and it's
specific to C (and to languages that borrowed from it). Other
languages use different syntax. It's entirely possible to have a
thorough understanding of hexadecimal without knowing about 0x.

Certainly any C programmer needs to know what 0x means, but it
shouldn't take more than a moment to learn it.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jul 14 '06 #12
The reference document you seek is called:
"INTERNATIONAL STANDARD ŠISO/IEC ISO/IEC 9899:1999 (E)
Programming languages - C"

and it costs $30 or so in PDF format. Its fairly expensive in printed form,
but you can probably run off a copy at Kinkos for a moderate price.

The section you are interested in is:
6. Language

With special ephasis on 6.5 Expressons and 6.7 Declarations
Thank you. I will look into it.
I should mention that most of your comments above are utter nonsense.
Oversimplifications, sure. As long as one works on a system where '0'
is 0x30, it is not really necessary to know that on some other system
it can be something else. For that matter, when I taught calculus to
non-science students, I just trashed the whole complex and fiddling
limit theory, and told them that division by zero gives infinity. Not
something I would do to math or physics students, but it worked in the
context. Brickbats welcome.

Jul 14 '06 #13
<il***@rcn.comwrote in message
news:11**********************@35g2000cwc.googlegro ups.com...
The reference document you seek is called:
"INTERNATIONAL STANDARD ŠISO/IEC ISO/IEC 9899:1999 (E)
Programming languages - C"

and it costs $30 or so in PDF format. Its fairly expensive in printed
form,
but you can probably run off a copy at Kinkos for a moderate price.

The section you are interested in is:
6. Language

With special ephasis on 6.5 Expressons and 6.7 Declarations
Thank you. I will look into it.
I should mention that most of your comments above are utter nonsense.
Oversimplifications, sure. As long as one works on a system where '0'
is 0x30, it is not really necessary to know that on some other system
it can be something else. For that matter, when I taught calculus to
non-science students, I just trashed the whole complex and fiddling
limit theory, and told them that division by zero gives infinity. Not
something I would do to math or physics students, but it worked in the
context. Brickbats welcome.

Teaching {for instance} to make '9' into a 9 by subtracting 48 is simply
wrong.
Right this minute, I am doing a build of a middleware product for IBM
mainframes. That C expression produces the wrong answer on that machine.

'9' - '0' produces the right decimal digit.
'9' - 48 does not produce the right decimal digit.

I remember something from "The Odd Couple", it was a court case where Oscar
Madison was the defendent and Felix Unger was defending him. Felix made an
interesting observation about the word 'assume'.

By dissecting the word, he came up with this:
'When you assume you make and [ass] out of [u] and [me].'

When you make unwarranted assumptions about what low level formats underly
data objects, you can get into a world of trouble. As you can see (from the
example above), the correct expression works just as well and is no more
complicated than the one that uses the unwarranted assumption.

Now, you can manipulate bits and bytes according to the formal definition of
the language itself, and you can be guaranteed of results, as the standard
itself defines how things ought to operate. But when you start to make
assumptions that are sometimes true, then eventually, you will get bonked by
it.

There are not a lot of one's complement machines around, so things like:
x&1 (Assumes 2's complement)
verses:
x%2 (works everywhere)
to test for odd numbers are probably OK [most of the time]. But in your
ASCII example, there is a very significant portion of the world's data
stored on IBM mainframe machines.

A big focus of this newsgroup is aimed at portable code. Since I program
for literally dozens of different hardware platforms continuously, it is
very valuable for me to have this focus. And to aim for a formal standard
to have guarantees about how things are supposed to work is a very good
engineering practice in general.
Jul 14 '06 #14
On 2006-07-14, il***@rcn.com <il***@rcn.comwrote:
At some point before attributions were snipped, Dann Corbit wrote:
>I should mention that most of your comments above are utter nonsense.

Oversimplifications, sure. As long as one works on a system where '0'
is 0x30, it is not really necessary to know that on some other system
it can be something else. For that matter, when I taught calculus to
non-science students, I just trashed the whole complex and fiddling
limit theory, and told them that division by zero gives infinity. Not
something I would do to math or physics students, but it worked in the
context. Brickbats welcome.
Similar to someone's "compiler for nonprogrammers" question, I have to
wonder why you'd have to teach calculus to non-science (by which I
assume you also mean non-math) students.

The basis of C is that you can write a program and it will work on a
SNES, a Commodore 64, and a robotic dragon from the future. It's a
fair bit more important than you'd think to show students how different
systems work, and how to make your code function no matter what the
architecture.

Endianness is vital, as is differently sized primitive types. Charsets
were becoming less important, but now we've got internationalization
and once again it's important that you aren't depending on ASCII.

--
Andrew Poelstra <http://www.wpsoftware.net/projects/>
To email me, use "apoelstra" at the above domain.
"You people hate mathematics." -- James Harris
Jul 14 '06 #15
il***@rcn.com writes:
[...]
Oversimplifications, sure. As long as one works on a system where '0'
is 0x30, it is not really necessary to know that on some other system
it can be something else. For that matter, when I taught calculus to
non-science students, I just trashed the whole complex and fiddling
limit theory, and told them that division by zero gives infinity. Not
something I would do to math or physics students, but it worked in the
context. Brickbats welcome.
As long as you know that '0' is '0', you don't need to know or care
that it happens to be 0x30 on your system. If you have an expression
of type char, and you know that its value is in the range '0' to '9',
you can get the integer value of that digit by subtracting '0':

char c = '5';
int n = c - '0';
/* n == 5 */

This is guaranteed to work because the standard requires the digit
characters '0' to '9' to have contiguous representations (it doesn't
make the same guarantee for letters).

Now, given that this is simpler, easier to remember, and more
portable, why should I care that '0' == 0x30 on some but not all
systems?

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jul 14 '06 #16
<il***@rcn.comwrote in message
>
>Or why converting a numeric CHAR into an INT involves
subtracting 48 -- and not 30, as previous example might suggest.

Who told you to subtract 30 ?
You have to subtract ' 0'.

48 is decimal value of '0'. In hexadecimal it is 0x30
>And you would have missed ' 0x' while you
were reading.
It should have been 0x30.

I know that. I was bringing up an example of a mistake someone
unfamiliar with hexadecimal may make.
Students do need to know that all variables in the computer are ultimately
binary, and that hexadecimal notation is a convenient way of making binary
numbers readable to humans, but nothing more.
They also need to know that ASCII is just an arbitrary set of mappings from
integers to English-language characters.

I would hope that these things are not presented as deep problems. They are
just a few basic facts you need to know before you start serious C
programming.

Data structures. on the other hand, are interesting, because different
structures have different characteristics. Some structures can be updated
very easily, others only with expensive operations. Some are easy to search,
others very slow. Some are easy to implement, others very tricky.
--
Buy my book 12 Common Atheist Arguments (refuted)
$1.25 download or $7.20 paper, available www.lulu.com/bgy1mm
Jul 14 '06 #17


Andrew Poelstra wrote On 07/14/06 15:30,:
[...]
The basis of C is that you can write a program and it will work on a
SNES, a Commodore 64, and a robotic dragon from the future. [...]
If you invoke U.B. on a robotic dragon, you'll
be *really* sorry about the ensuing nasal demons ...

--
Er*********@sun.com

Jul 14 '06 #18
On 14 Jul 2006 12:16:15 -0700, il***@rcn.com wrote:
For that matter, when I taught calculus to
non-science students, I just trashed the whole complex and fiddling
limit theory, and told them that division by zero gives infinity
I'm not sure what you taught them, but it wasn't calculus.

--
Al Balmer
Sun City, AZ
Jul 14 '06 #19
il***@rcn.com wrote:
I am supposed to teach an introductory C course with an unusual slant,
and have trouble finding an appropriate textbook. The course will begin
traditionally enough with variables, loops, conditionals, structures,
pointers and fopen/fclose. Beyond that, however, every course and
textbook I had seen is heavy on data *structures*, and touches on other
topics lightly if at all. Whereas I need to stress data *types*,
converting them one into the other, and bit manipulation. By the end of
the course I do not care if my students know what a linked list is, let
alone a binary tree, but they must have good understanding of ASCII,
binary and hexadecimal. For example, it must clear to them why number
353 is actually stored as 0x01 0x61 if it's and INT, but 0x33 0x35 0x33
if it's a CHAR*. Or why converting a numeric CHAR into an INT involves
subtracting 48 -- and not 30, as previous example might suggest.
To any student of ilya2:

Run away. Now. Don't look back.

Now go find a teacher who knows more than sweet Fanny Adams about the
subject he's teaching, 'cause that one didn't.

Richard
Jul 17 '06 #20
"Dann Corbit" <dc*****@connx.comwrote:
<il***@rcn.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
Is there a textbook with such emphasis on data types, bits, and
hexadecimal, or am I doomed to writing my own?

The reference document you seek is called:
"INTERNATIONAL STANDARD ŠISO/IEC ISO/IEC 9899:1999 (E)
Programming languages - C"

and it costs $30 or so in PDF format. Its fairly expensive in printed form,
<http://eu.wiley.com/WileyCDA/WileyTitle/productCd-0470845732.htmlis
about $60, and has TC1. Other than that, n1124.pdf is TTBOMK still free,
and includes both TCs, but is a public draft.

Richard
Jul 17 '06 #21

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Martin MOKREJŠ | last post by:
Hi, I'm looking for some easy way to do something like include in c or PHP. Imagine I would like to have: cat somefile.py a = 222 b = 111 c = 9
0
by: JimC | last post by:
Database design is well covered in undergrad CS. But does anyone know of a textbook that deals with the design of database servers (and probably touches on databases themselves), and perhaps...
8
by: Alan J. Flavell | last post by:
OK, I guess I'm about ready to expose this page for public discussion: http://ppewww.ph.gla.ac.uk/~flavell/charset/i18n-weft.html Please concentrate on the content. I'm well aware that my old...
6
by: bambooforest | last post by:
Hi all, I'm from a Linguistics background and am new(er) to programming. Could someone recommend a book or resource that teaches programming aspects with Python? Python I hear is a very...
13
by: Grant Edwards | last post by:
I need to interpolate an irregularly spaced set of sampled points: Given a set of x,y,z points, I need to interpolate z values for a much finer x,y grid. I tried using the scipy sandbox delaunay...
63
by: time.swift | last post by:
Coming from a C++ / C# background, the lack of emphasis on private data seems weird to me. I've often found wrapping private data useful to prevent bugs and enforce error checking.. It appears...
0
by: AMDRIT | last post by:
I am looking for better concrete examples, as I am a bit dense, on design patterns that facilitate my goals. I have been out to the code project, planet source code, and microsoft's patterns and...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.