+ Reply to Thread
Results 1 to 15 of 15

Thread: What does 0x2F mean?

  1. #1
    chris414 Good chris414 Good chris414 Good
    Join Date
    Apr 2009
    Posts
    113

    Default What does 0x2F mean?

    What does the "0x" in "0x2F" mean? I get that the "2F" is hexadecimal, but what relevance does the "0x" have?


  2. #2
    Help us help you blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent
    Join Date
    Jan 2007
    Location
    Toronto, Canada
    Posts
    10,709
    Blog Entries
    5

    Default

    0x means a hexadecimal number follows
    Bill
    Smart Kits build Smart People

    http://www.blueroomelectronics.com/

  3. #3
    Papabravo Excellent Papabravo Excellent Papabravo Excellent Papabravo Excellent Papabravo Excellent Papabravo Excellent Papabravo Excellent
    Join Date
    Mar 2006
    Location
    Michigan, USA (GMT-5)
    Posts
    2,892

    Default

    It is used to distinguish between 'AF' the alphabetic string and 0xAF the hexidecimal number. The number starts with a digit which has the same value in any number base.
    We never have time to do it right; but we always have time to do it over.

  4. #4
    Triode Good Triode Good Triode Good
    Join Date
    Feb 2009
    Location
    Milwaukee Area
    Posts
    533
    Blog Entries
    4

    Default

    and 0b will often proceed binary numbers, just FYI
    Last edited by Triode; 25th June 2009 at 10:39 PM.

  5. #5
    Wp100 Good Wp100 Good Wp100 Good
    Join Date
    Feb 2009
    Location
    England
    Posts
    262

    Default

    Hi,


    In that little code example I sent you will see on the first line the code LIST P=18F2550,r=hex - radix=hex - meaning that any uncoded number will be treated as a hex value - so if you had movlw 16 it would be recognised as hex 0x16.

    It is also quite popular for the radix=dec when 16 is simply that, but more commonly coded as .16 - the full point denoting a decimal value follows.

    Even when using the Radix statement, to avoid problems its perhaps wise to always code your values accordingly 0xhex or .dec or binary b'01010101'

  6. #6
    solarwind Newbie
    Join Date
    Dec 2008
    Posts
    33

    Default

    Quote Originally Posted by chris414 View Post
    What does the "0x" in "0x2F" mean? I get that the "2F" is hexadecimal, but what relevance does the "0x" have?
    As many have said, the 0x (in many languages including C and PIC ASM) is a prefix added to hexadecimal numbers. 0b means binary and 0d usually designates decimal, although decimal is usually default and assumed to be decimal without any prefix. 0O (zero-oh) usually means octal :P

  7. #7
    chris414 Good chris414 Good chris414 Good
    Join Date
    Apr 2009
    Posts
    113

    Default

    thanks a lot

  8. #8
    Super Moderator Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent
    Join Date
    Nov 2003
    Location
    Derbyshire, UK
    Posts
    29,793

    Default

    Quote Originally Posted by chris414 View Post
    thanks a lot
    If you read the MPASM/MPLAB help files, all these things are explained.
    PIC programmer software, and PIC Tutorials at:
    http://www.winpicprog.co.uk

  9. #9
    Triode Good Triode Good Triode Good
    Join Date
    Feb 2009
    Location
    Milwaukee Area
    Posts
    533
    Blog Entries
    4

    Default

    If you read the MPASM/MPLAB help files, all these things are explained.
    I sometimes think a helpfile that lists all the help files and explains what kind of stuff they cover is in order.

  10. #10
    skeeterb Newbie
    Join Date
    Apr 2007
    Location
    USA
    Posts
    178

    Default

    If you want to figure out the binary/hexadecimal thing use this chart I created. I constantly use it when I'm writing code for PICs. It helps me speed up the coding after I create a chart of how I want ports to be either High or Low.


    heres a little bit of sample code

    Code:
    movlw 0x0A
    movwf PortB
    
    0x0A means 00001010 in Binary which means Pins 1 and 3 are High and the rest are Low
    Attached Files
    Last edited by skeeterb; 26th June 2009 at 02:10 PM.
    This is the way the world ends,
    This is the way the world ends,
    This is the way the world ends,
    Not with a BANG
    But with a BELCH

    BURRRRRRRRRRPPPPPPP

  11. #11
    Mike, K8LH Excellent Mike, K8LH Excellent Mike, K8LH Excellent Mike, K8LH Excellent Mike, K8LH Excellent Mike, K8LH Excellent Mike, K8LH Excellent
    Join Date
    Jan 2005
    Location
    Michigan, USA
    Posts
    2,522

    Default

    Doesn't the Windows Calculator provide a simple mechanism for looking at a number as decimal, binary, or hex?

  12. #12
    skeeterb Newbie
    Join Date
    Apr 2007
    Location
    USA
    Posts
    178

    Default

    I wanted a quick reference guide I can use when I'm coding. All I have to do is do a search in my hex/binary chart and go straight to the correct hex code
    This is the way the world ends,
    This is the way the world ends,
    This is the way the world ends,
    Not with a BANG
    But with a BELCH

    BURRRRRRRRRRPPPPPPP

  13. #13
    Mr RB Excellent Mr RB Excellent Mr RB Excellent Mr RB Excellent Mr RB Excellent Mr RB Excellent Mr RB Excellent
    Join Date
    Jul 2008
    Location
    Out there
    Posts
    1,761

    Default

    Quote Originally Posted by Mike, K8LH View Post
    Doesn't the Windows Calculator provide a simple mechanism for looking at a number as decimal, binary, or hex?
    I wrote a little free windows program that does dec/hex/binary conversion to 32bits and has ascii key codes displayed etc etc;

    "HexCon" Hex-Decimal-Binary converter

  14. #14
    3v0
    3v0 is online now
    3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent 3v0 Excellent
    Join Date
    Jul 2006
    Location
    USA
    Posts
    6,464
    Blog Entries
    11

    Default

    Quote Originally Posted by skeeterb View Post
    I wanted a quick reference guide I can use when I'm coding. All I have to do is do a search in my hex/binary chart and go straight to the correct hex code
    The hex to bin and bin to hex should be engraved deeply into your brain if you want to work in embedded systems. Along the line of 2+3=5 type of recall. You need to know 1011 is B and 1101 is D without thinking.

    The time it takes to learn the 16/32 conversion will be paid back to you many times.
    Please post questions to the forums. PM's are for personal communication.

    BCHS/3v0's Tutorials
    Junebug USB PIC programmer kit., USB Bit Whacker,
    The 15 Minute Printed Circuit Board! (+drill time)

  15. #15
    Triode Good Triode Good Triode Good
    Join Date
    Feb 2009
    Location
    Milwaukee Area
    Posts
    533
    Blog Entries
    4

    Default

    I'm just not sure why you made the chart go up to 2 digits of hex and 8 of binary. Hex converts in nice 4 bit chunks, thats why its used with computers. You can look at any hex digit and know what the corresponding block of 4 binary bits ("nibble") is without knowing the digits that proceed it. Conversly, if I tell you "I have a decimal number, the fifth digit is 9" you can't get the corresponding binary for that part of the number.
    Last edited by Triode; 26th June 2009 at 05:42 PM.

+ Reply to Thread

Tags for this Thread