Thread: Hex

  1. #16
    Registered User
    Join Date
    Jan 2008
    Posts
    124
    the above program prints
    0012FF60
    i was looking to get it to print something with an x in the middle
    ex. 0x40tt

  2. #17
    Registered User
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    217
    It's pretty basic. All you do is add "0x" in front of the "%p"

  3. #18
    Registered User
    Join Date
    Jan 2008
    Posts
    124
    i am not asking for you to do my hemework. I am just trying to figure some things out based on my notes and it is not working out. All i want is for someone to explain to me what I am doing wrong.
    I do appreciate the help.

  4. #19
    Registered User
    Join Date
    Jan 2008
    Posts
    124
    i was looking over some notes that i have and all we used was %p without 0X and it was still printing hex.

  5. #20
    Registered User
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    217
    Quote Originally Posted by goran00 View Post
    i was looking over some notes that i have and all we used was %p without 0X and it was still printing hex.
    I think it's been explained enough.

  6. #21
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,412
    i was looking over some notes that i have and all we used was %p without 0X and it was still printing hex.
    It could be that that particular implementation adds a "0X".

    Hexadecimal is a number base. The "0x" is just a notation used in languages derived from C. Mathematical notation uses a subscript of "16", other programming languages append a "h". But the representation of the number is hexadecimal, regardless of what is used to denote the base.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #22
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by laserlight View Post
    It could be that that particular implementation adds a "0X".

    Hexadecimal is a number base. The "0x" is just a notation used in languages derived from C. Mathematical notation uses a subscript of "16", other programming languages append a "h". But the representation of the number is hexadecimal, regardless of what is used to denote the base.
    And whilst it is POSSIBLE for the implementation of the C library (the code inside the printf function) to produce something other than hex output, it's unlikely that you'll find such a thing. If someone is interested in the value of a pointer (the address it contains) it makes much more sense to have it in hex, as computer memory addresses are almost always expressed in hex in debuggers etc.

    So it is unlikely that the value will be printed as a decimal number for example. Of course, it may not be a plain hex number even then, for example in a 16-bit x86 system (e.g. Turbo C on DOS) a (far) pointer would be XXXX:YYYY where XXXX is the segment base address, and YYYY is the offset, the actual address being (XXXX << 4) + YYYY.

    I've also seen some printf() implementations putting 0x in front of the pointer value, and other printf implementations that do NOT put 0x at the front.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ascii to hex and hex to Ascii
    By beon in forum C Programming
    Replies: 1
    Last Post: 12-26-2006, 06:37 AM
  2. Hex Editing help and information please...
    By SG57 in forum C Programming
    Replies: 9
    Last Post: 06-25-2006, 12:30 AM
  3. Replies: 11
    Last Post: 03-24-2006, 11:26 AM
  4. Replies: 3
    Last Post: 01-23-2006, 07:25 PM
  5. Is binary HEX?
    By Budgiekarl in forum Tech Board
    Replies: 11
    Last Post: 11-23-2003, 09:02 AM