public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* using hex in gcc
@ 2012-06-06 17:14 dhpant2806
  2012-06-06 20:33 ` Ángel González
  0 siblings, 1 reply; 4+ messages in thread
From: dhpant2806 @ 2012-06-06 17:14 UTC (permalink / raw)
  To: gcc-help


i want to test some code having hex variable in gcc.how can i do it

-- 
View this message in context: http://old.nabble.com/using-hex-in-gcc-tp33971305p33971305.html
Sent from the gcc - Help mailing list archive at Nabble.com.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: using hex in gcc
  2012-06-06 17:14 using hex in gcc dhpant2806
@ 2012-06-06 20:33 ` Ángel González
  2012-06-07  6:34   ` dhruv pant
  0 siblings, 1 reply; 4+ messages in thread
From: Ángel González @ 2012-06-06 20:33 UTC (permalink / raw)
  To: dhpant2806; +Cc: gcc-help

On 06/06/12 19:14, dhpant2806 wrote:
> i want to test some code having hex variable in gcc.how can i do it
What do you mean? Your question doesn't make much sense.
You don't have 'hex' variables. The way the values are stored is specific
to the architecture you are compiling to (just think that they are
"stored as bits").
Decimal, hexadecimal, binary, etc. is how we input them (in writing the
literals)
or output them.

I have no idea if this is what you wanted, but take a look at the
following program:

#include <stdio.h>

int main() {
    int variableA = 42;
    int variableB = 0x33;
    printf("Variable A: %d decimal - %x hexadecimal\n", variableA,
variableA);
    printf("Variable B: %d decimal - %x hexadecimal\n", variableB,
variableB);
    return 0;
}

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: using hex in gcc
  2012-06-06 20:33 ` Ángel González
@ 2012-06-07  6:34   ` dhruv pant
  2012-06-07 11:06     ` Andrew Haley
  0 siblings, 1 reply; 4+ messages in thread
From: dhruv pant @ 2012-06-07  6:34 UTC (permalink / raw)
  To: Ángel González; +Cc: gcc-help

thanks got it...i was actually  thinking in some other way....
so basically everything is actually stored in binary form.it's for our
convenience and readability that we are converting them to hex or
decimal.....
so suppose...
unsigned int i=10
printf("%x",i) //this will print the hex equivalent of 10?

On 6/7/12, Ángel González <keisial@gmail.com> wrote:
> On 06/06/12 19:14, dhpant2806 wrote:
>> i want to test some code having hex variable in gcc.how can i do it
> What do you mean? Your question doesn't make much sense.
> You don't have 'hex' variables. The way the values are stored is specific
> to the architecture you are compiling to (just think that they are
> "stored as bits").
> Decimal, hexadecimal, binary, etc. is how we input them (in writing the
> literals)
> or output them.
>
> I have no idea if this is what you wanted, but take a look at the
> following program:
>
> #include <stdio.h>
>
> int main() {
>     int variableA = 42;
>     int variableB = 0x33;
>     printf("Variable A: %d decimal - %x hexadecimal\n", variableA,
> variableA);
>     printf("Variable B: %d decimal - %x hexadecimal\n", variableB,
> variableB);
>     return 0;
> }
>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: using hex in gcc
  2012-06-07  6:34   ` dhruv pant
@ 2012-06-07 11:06     ` Andrew Haley
  0 siblings, 0 replies; 4+ messages in thread
From: Andrew Haley @ 2012-06-07 11:06 UTC (permalink / raw)
  To: gcc-help

On 06/07/2012 07:33 AM, dhruv pant wrote:
> thanks got it...i was actually  thinking in some other way....
> so basically everything is actually stored in binary form.it's for our
> convenience and readability that we are converting them to hex or
> decimal.....
> so suppose...
> unsigned int i=10
> printf("%x",i) //this will print the hex equivalent of 10?

Exactly.  Pocket calculators usually store numbers in decimal,
because for them most of the work is in the I/O.  Computers
usually store numbers in binary: how you print it is up to you.

Andrew.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-06-07 11:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-06 17:14 using hex in gcc dhpant2806
2012-06-06 20:33 ` Ángel González
2012-06-07  6:34   ` dhruv pant
2012-06-07 11:06     ` Andrew Haley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).