[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Hex

Posted on 1998-12-04
4
Medium Priority
?
635 Views
Last Modified: 2011-10-03
I am using Visual C++ 5.0 and am in Dialog mode.

I am trying to convert numbers to Hex. I am using this statement and would like to know how to display the number in hex.

SetDlgItemInt(IDC_STATIC,m_number);

I would also like to know how to recieve a hex number from and EDIT box.

Thanks
Randy
0
Comment
Question by:randyg
[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
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
Answers2000 earned 200 total points
ID: 1179213
Say the number is an int

1. Steps are to convert it to a string, e.g.

(a) if want a CString

int nNumber ;
CString str ;
str.Format( "%x", nNumber )

or
(b) if want a char[] array

int nNumber
char str[256] ;
sprintf( str, "%x", nNumber ) ;

or

(c) another way to do (b) is to use itoa, this allows you to specify the base (e.g. you can use this to convert a integer into any reasonable base, e.g.

_itoa( nNumber, str /* char array */, 16 ) ; // 16 = base 16

2. Set the string into the dialog (works with CString or char array)

SetDlgItemText( IDC_STATIC, str ) ;


See my next comment for extracting from edit boxes.


0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1179214
Right you can can use SetDlgItemText to place text on a static or edit. (simply replace IDC_STATIC with the id of the control)

To get the current text from an edit use GetDlgItemText, then use sscanf to get convert a hex number to a integer

char szOutput[256] ;
GetDlgItemText( IDC_EDIT, szOutput, sizeof szOutput ) ;
int nNumber ;
sscanf( szOutput, "%x", &nNumber ) ;


incidentally %x means use lower case letters in hex numbers, %X means use upper case

I think that's everything you need ?
0
 
LVL 1

Expert Comment

by:The_Brain
ID: 1179215
I agree with Answers2000,  itoa would be a good option, I have written a base x program, which converts any number to any base 2-36.  input a number in anybase and output. If you want it you can have it, just E-mail me.  g_dutoit@hotmail.com.  


0
 

Author Comment

by:randyg
ID: 1179216
Great answers!!!!!

Thanks
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

656 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