www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/02/17/19:55:17

From: nikki AT gameboutique DOT co (nikki)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Char/unsigned/unsigned char conversion problems.
Date: 17 Feb 1997 21:48:11 GMT
Organization: GameBoutique Ltd.
Lines: 23
Message-ID: <5eajmr$j08@flex.uunet.pipex.com>
References: <5e6mqp$6ah AT lion DOT cs DOT latrobe DOT edu DOT au>
NNTP-Posting-Host: www.gameboutique.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

> I was assuming that the upper byte would be zeroed in the conversion (unsigned)Ch.
> I.E.
> char : 10110011 -----> unsigned : 0000000010110011
> 
> Is this assumption wrong and the upper byte could be anything?

i didn't understand most of this as it was in c++ but that part above is
wrong.

char is by default signed, so having the higher bit set as 1 like that will
be treated as a negative number. then you try to convert a negative number
into an unsigned short. actually i'm not sure what that will do, it might
append leading 1's instead of 0's as you expect, i always avoid those sort
of problems by ensuring i have an unsigned char in the first place before
conversion :)

regards,
nik


-- 
Graham Tootell           
nikki AT gameboutique DOT com  

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019