From owner-freebsd-questions@FreeBSD.ORG Sun Oct 16 21:52:05 2011 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8B3E3106566B for ; Sun, 16 Oct 2011 21:52:05 +0000 (UTC) (envelope-from bonomi@mail.r-bonomi.com) Received: from mail.r-bonomi.com (mx-out.r-bonomi.com [204.87.227.120]) by mx1.freebsd.org (Postfix) with ESMTP id 5B4588FC14 for ; Sun, 16 Oct 2011 21:52:04 +0000 (UTC) Received: (from bonomi@localhost) by mail.r-bonomi.com (8.14.4/rdb1) id p9GLpZHZ064824 for freebsd-questions@freebsd.org; Sun, 16 Oct 2011 16:51:35 -0500 (CDT) Date: Sun, 16 Oct 2011 16:51:35 -0500 (CDT) From: Robert Bonomi Message-Id: <201110162151.p9GLpZHZ064824@mail.r-bonomi.com> To: freebsd-questions@freebsd.org In-Reply-To: <20111016212628.GA30284@thought.org> Subject: Re: need to check for hex in C: how/ X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 16 Oct 2011 21:52:05 -0000 > From owner-freebsd-questions@freebsd.org Sun Oct 16 16:27:46 2011 > Date: Sun, 16 Oct 2011 14:26:31 -0700 > From: Gary Kline > To: FreeBSD Mailing List > Cc: > Subject: need to check for hex in C: how/ > > > if n == 15 and x is the int. i can say > > if ((int)x == 15) Or to check if x == 'A' i can cast x to (char)x. > > what's the syntax to chec if x is , say, 32/ The advice from my computer-science professor was 'try it and find out'. It doesn't matter what anybody _says_ it is, the only thing that matters is what the computer (or, to be precise, the compiler) accepts? Now, for some information that you could/should get from any elementary book on C programming ("The C Programming Language", by Kerningan and Ritchie [r.i.p., this last week] is recommended): In general, you don't need _any_ explicit casts for those situations. C does 'automatic' promotion of numeric items so they have comparable 'width' for comparisons. For more details, see the 'fine manual' mentioned above.