Return-Path: william@bourbon.usc.edu Delivery-Date: Wed Oct 15 19:29:14 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on merlot.usc.edu X-Spam-Level: X-Spam-Status: No, score=-2.3 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.3 Received: from bourbon.usc.edu (bourbon.usc.edu [128.125.9.75]) by merlot.usc.edu (8.14.1/8.14.1) with ESMTP id m9G2TEWK010139 for ; Wed, 15 Oct 2008 19:29:14 -0700 Received: from bourbon.usc.edu (localhost.localdomain [127.0.0.1]) by bourbon.usc.edu (8.14.2/8.14.1) with ESMTP id m9G2bKoj010150 for ; Wed, 15 Oct 2008 19:37:20 -0700 Message-Id: <200810160237.m9G2bKoj010150@bourbon.usc.edu> To: cs551@merlot.usc.edu Subject: Re: assigning short to char Date: Wed, 15 Oct 2008 19:37:20 -0700 From: Bill Cheng Someone wrote: > How can I assign a short value to a char? "short" in C/C++ means "short int" and it is two bytes long. > I tried something like this > > char x = (char) 0xAA; > > But when I again do... > > if(x==(char)0xAA), it always returns false. In the above code, you are not trying to assign a "short" to a char! If you are trying to assign 0xaa to a char, I think you are doing the right thing. I don't see why it would not work. May be you should set a break point right before the if statement and print out x and see if it equals 0xaa. -- Bill Cheng // bill.cheng@usc.edu