🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.unix
Article #1334

Re: How to convert a char into an int from 0 through 255?

#1334
From: Walter Bright
Date: Mon, 08 Jan 1990 19:43
20 lines
1163 bytes
From: bright@Data-IO.COM (Walter Bright)

In article <498@longway.TIC.COM> uunet!stealth.acf.nyu.edu!brnstnd (Dan Bernstein) writes:
<I'd like a solution that is both conformant and
<portable in the real world.
<Does (int) (unsigned int) ch do the trick?
No.

<What about (int) (unsigned char)?
Yes, assuming chars are 8 bits. But be warned, some older K&R compilers I've
run across do not do that cast correctly, even though the expression is correct.

I prefer using:
	char c;
	int i;
	i = c & 0xFF;	/* assuming chars >= 8 bits	*/

P.S. I don't care about 1's complement machines.

Volume-Number: Volume 18, Number 12
Technical Details
Message-ID: <502@longway.TIC.COM>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!longway!std-unix
References: <498@longway.TIC.COM>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!longway!std-unix
From: bright@Data-IO.COM (Walter Bright)
Newsgroups: comp.std.unix
Subject: Re: How to convert a char into an int from 0 through 255?
Message-ID: <502@longway.TIC.COM>
Date: 8 Jan 90 19:43:06 GMT
References: <498@longway.TIC.COM>
Sender: std-unix@longway.TIC.COM
Reply-To: bright@Data-IO.COM (Walter Bright)
Organization: Data I/O Corporation; Redmond, WA
Lines: 20
Approved: jsq@longway.tic.com (Moderator, John S. Quarterman)