Article View: comp.std.unix
Article #1322Re: How to convert a char into an int from 0 through 255?
From: T. William Wells
Date: Sun, 07 Jan 1990 07:02
Date: Sun, 07 Jan 1990 07:02
29 lines
1672 bytes
1672 bytes
From: bill@twwells.com (T. William Wells)
In article <498@longway.TIC.COM> uunet!stealth.acf.nyu.edu!brnstnd (Dan Bernstein) writes:
: From: brnstnd@stealth.acf.nyu.edu
:
: The question is self-explanatory. This is a practical question as well
: as a theoretical one: I'd like a solution that is both conformant and
: portable in the real world. Does (int) (unsigned int) ch do the trick?
: What about (int) (unsigned char)?
Excuse, but this is purely a C question, so I've directed
followups to comp.lang.c.
[ I'm not sure I agree, but I don't see comp.std.unix people clamoring
to answer this question, so let's send it to comp.lang.c to see if there
is more interest there. -mod ]
Anyway, I don't think that either is
guaranteed. One that is, assuming that the character is not in a
register, is: *(unsigned char *)&ch.
(NB: a char might be converted to a number larger than 255 if
characters are larger than eight bits.)
---
Bill { uunet | novavax | ankh | sunvice } !twwells!bill
bill@twwells.com
Volume-Number: Volume 18, Number 15
Technical Details
Message-ID:
<505@longway.TIC.COM>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!snorkelwacker!apple!longway!std-unixReferences:
<498@longway.TIC.COM>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!snorkelwacker!apple!longway!std-unix From: bill@twwells.com (T. William Wells) Newsgroups: comp.std.unix,comp.lang.c Subject: Re: How to convert a char into an int from 0 through 255? Message-ID: <505@longway.TIC.COM> Date: 7 Jan 90 07:02:39 GMT References: <498@longway.TIC.COM> Sender: std-unix@longway.TIC.COM Reply-To: bill@twwells.com (T. William Wells) Followup-To: comp.lang.c Organization: None, Ft. Lauderdale, FL Lines: 29 Approved: jsq@longway.tic.com (Moderator, John S. Quarterman)