Solved

assigning hexadecimal value

Posted on 2006-11-19
6
1,478 Views
Last Modified: 2013-11-17
hi,

i wanted to ask if there is a way to assign a hexa decimal value to a variable directly in c++ ???

waiting for replies
fa!
0
Comment
Question by:fatimao
  • 3
  • 2
6 Comments
 
LVL 9

Expert Comment

by:alkisg
ID: 17975686
int a = 0x1234;
0
 

Author Comment

by:fatimao
ID: 18005905
yup thanks its working! but we cant assign the hexa-decimal address ... right?
like &a = 0x1234

Is there a way to move a variable (allocate variable) adress of your own choice?

 best regards
0
 
LVL 9

Expert Comment

by:alkisg
ID: 18006270
No, you can't declare a variable to occupy a specific memory address.
In Pascal you can do
var
  a: byte absolute $A000:0;
but not in C.

But that's what pointers are for:
int *a = 0x1234;
This is a pointer to the memory with address 0x1234.
Then you can do
*a = 5;

This will result to
RAM[0x1234] = 5
0
 

Author Comment

by:fatimao
ID: 18012106
thanx for a nice reply but ...
i tried it in visual studios and this line "int *a = 0x1234;" gives error "cannot convert from const int to int *"

so we can't even assign hexa decimal address to a pointer in c?

please clear the confusion
0
 
LVL 9

Accepted Solution

by:
alkisg earned 50 total points
ID: 18012487
Sorry, you also need a typecast:
int *a = (int *)0x1234;
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
My eclipse editor won't start ? 4 154
How to debug CodeIgniter (PHP) 7 392
Eclipse XML hightlightning 5 57
What is Codeanywhere used for and can EE provide example of use 9 216
Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question