Thread: Can I store a decimal value in memory as shown below?

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    44

    Can I store a decimal value in memory as shown below?

    I have successfully stored hex values to memory using the method below and wanted to know if I can store decimal values as well.
    Thanks.

    Code:
    *(int*)(0xeff000040) = 405;

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Any numeric literal in your program can be in any format you want it to be, because you're the only one who sees it -- the preprocessor converts it into a token for whatever-kind-of-number-it-gets-stored-as before the compiler even sees it.

    (This post should not be read as condoning the above line of code in any way.)

  3. #3
    Registered User
    Join Date
    Dec 2017
    Posts
    1,628
    There's no such thing as storing a "hex" or "decimal" value. The value is stored internally as binary. You can enter it (or print it) in any base you wish, usually hex, octal, or possibly binary. But the value is the same in every case. It's just a different way of writing it.
    405 = 0625 = 0x195 = 0b110010101
    A little inaccuracy saves tons of explanation. - H.H. Munro

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 07-10-2012, 04:28 AM
  2. Free Store of memory
    By George2 in forum C++ Programming
    Replies: 6
    Last Post: 11-12-2007, 02:27 PM
  3. How to store any value in Memory (inside chip) ?
    By burhanahmad in forum C Programming
    Replies: 3
    Last Post: 04-29-2005, 09:48 AM
  4. bank switching to store memory
    By muttski in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 10-18-2002, 03:51 PM
  5. How do i store a file in memory?
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 01-30-2002, 07:05 PM

Tags for this Thread