Solved

assigning hexadecimal value

Posted on 2006-11-19
6
1,489 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

738 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