Thread: if statement with hex variable

  1. #1
    Registered User
    Join Date
    Sep 2009

    if statement with hex variable

    It is possible to use hex values with the if statement


    if (value == f)
    where f is 15 in hex and not the ascii value. i know i could simply have value equal 15 but for readability i would prefer the hex to be displayed.

  2. #2
    Registered User
    Join Date
    Jun 2005
    Yep. Use the 0x prefix.

        if (value = 0x15)    /*   0x15 is 21 in decimal  */
    Also a prefix of 0 (no x) is octal - base 8. So 017 is actually the value 15 (decimal). It is a fairly common mistake for beginners to expect that 017 is in decimal, not octal.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 11
    Last Post: 04-14-2010, 09:32 PM
  2. Statement inside a statement.
    By JOZZY& Wakko in forum C Programming
    Replies: 15
    Last Post: 11-05-2009, 03:18 PM
  3. declare variable in case statement
    By Marksman in forum C Programming
    Replies: 9
    Last Post: 11-13-2008, 03:32 AM
  4. if statement reads char value as variable
    By yougene in forum C Programming
    Replies: 2
    Last Post: 07-29-2007, 11:16 PM
  5. embedding variable inside sql statement
    By WaterNut in forum C++ Programming
    Replies: 1
    Last Post: 06-08-2004, 02:43 PM