473,394 Members | 1,696 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to convert Hexadecimal number to decimal number

Hi everyone...

I have a data with both decimal and Hexadecimal numbers. I am extracting the required data from for analysis with the help of MINITAB 15. The problem is MINITAB 15 is not accepting the Hexdec data, so while extracting itself I need to convert the data from Hex to decimal. For extracting the data I am using Visual Studios "VC++" can anyone help me how to do the conversion.

Thanks in advance

Regards
Siva
Mar 18 '09 #1
8 9942
weaknessforcats
9,208 Expert Mod 8TB
You will need to write a function that can convert a string (from your file) into an integer where the string has a hexadecimal number.

The conversion is straightforward. The hex number 1AB is just 1 * 256 + 10 * 16 + 11 * 1. 256 is 16 squared.

Your function will have a loop and you will start at the first character of the string. This is the leftmost or most significant digit of the hex number. You will need to count the characters in the value to get the correct power of 16 for this leftmost digit. Then you convert the character to a hex integer. Then multiply by the power of 16 you just calculated. Add this to your total. Next, move to the second characterof the string and divide your power of 16 by 16 and repeat the conversion steps. When you get ot the end of the string, your are done. Finally, return your total as an unsigned interger (hex numbers cannot be negative).
Mar 18 '09 #2
donbock
2,426 Expert 2GB
Take a look at the man pages for standard library functions strtol and strtoul.
Mar 18 '09 #3
You will need to write a function that can convert a string (from your file) into an integer where the string has a hexadecimal number.

The conversion is straightforward. The hex number 1AB is just 1 * 256 + 10 * 16 + 11 * 1. 256 is 16 squared.

Your function will have a loop and you will start at the first character of the string. This is the leftmost or most significant digit of the hex number. You will need to count the characters in the value to get the correct power of 16 for this leftmost digit. Then you convert the character to a hex integer. Then multiply by the power of 16 you just calculated. Add this to your total. Next, move to the second characterof the string and divide your power of 16 by 16 and repeat the conversion steps. When you get ot the end of the string, your are done. Finally, return your total as an unsigned interger (hex numbers cannot be negative).
Thank you for the reply. To be frank I am not that much good at programming, I understood each and every line of your reply but not able to write code for that. I have tried but got stuck at "how to call individual string values and how to multiply with the reducing power of 16"..I will be very much helpfull if you help me regarding this

Thank you

Regards
Siva
Mar 19 '09 #4
JosAH
11,448 Expert 8TB
If you're using C have a look at the %i or %x format specifiers; if you're using C++ have a look at the hex manipulator.

kind regards,

Jos
Mar 19 '09 #5
Andr3w
42
Hey mate,

You can check also this link http://en.wikipedia.org/wiki/Hexadecimal which besides historical information gives you information on how to convert hex values to other systems ( not only decimal ) and the opposite.

Hope this helps
Mar 19 '09 #6
whodgson
542 512MB
Another way of explaining it from:
(Programming with C++ John R Hubbard) sets out the algorithm for
h[k].......h[2]h[1]h[0]:
1. Set x = 0.
2, Set j = k+1 (actual number of bits in the hex string)
3. Subtract 1 from j.
4. Multiply x by 16.
5. Add h[j] to x.
6. If j>0,repeat steps 3 - 6.
7. Return x.
example: convert f4d9 to decimal.
--------------------------------------------------------
j ....... h[j] .............x=2.x + h[j]
---------------------------------------------------------
4 ............................................0
3 ......... f ............... 16.0+ f = 15 ......[16.0 ==16 times 0]
2 ......... 4 ............16.15+4 = 244
1 ......... d .......16.244+13 = 3917
0 ......... 9 .......16.3917 + 9 = 62,681
so f4d9 (base 16) = 62681 (base 10)
Hope this helps
Mar 22 '09 #7
whodgson
542 512MB
The formula shown for x in the last thread is wrong.
Instead of x=2.x +h[j] it should have been x=16.x + h[j].
The trace of the algorithm is still correct.
Hope no injuries have resulted.
Mar 23 '09 #8
ya there was no injuries and no wounds...itz perfect..
Thanks a lot for everyone!

c u all in other/next thread...ciao
Mar 25 '09 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Hako | last post by:
I try this command: >>> import string >>> string.atoi('78',16) 120 this is 120 not 4E. Someone can tell me how to convert a decimal number to hex number? Can print A, B, C,DEF. Thank you.
9
by: FalkoG | last post by:
Hello colleague I want to convert a floating number for example 5236.9856982 to a hexadecimal number. I'd tried several things but my problem is to convert the position after decimal point. I...
13
by: muss | last post by:
how to convert decimal number in a hexadecimal number using C? Please help me. Thanks.
15
by: jaks.maths | last post by:
How to convert negative integer to hexadecimal or octal number? Ex: -568 What is the equivalent hexadecimal and octal number??
7
by: elliotng.ee | last post by:
I have a text file that contains a header 32-bit binary. For example, the text file could be: %%This is the input text %%test.txt Date: Tue Dec 26 14:03:35 2006...
6
by: sweeet_addiction16 | last post by:
hello Im writin a code in c... can sum1 pls help me out in writing a c code to convert decimalnumber to hexadecimal number.The hexadecimal number generated has to be an unsigned long.
10
by: cmdolcet69 | last post by:
Public ArrList As New ArrayList Public bitvalue As Byte() Public Sub addvalues() Dim index As Integer ArrList.Add(100) ArrList.Add(200) ArrList.Add(300) ArrList.Add(400) ArrList.Add(500)
8
by: te509 | last post by:
Hi guys, does anybody know how to convert a long sequence of bits to a bit-string? I want to avoid this: '949456129574336313917039111707606368434510426593532217946399871489' I would...
5
by: raghavendrap | last post by:
$tmp = 0xc0211082; $tmp1 = 0xc0000082; Hello friends, I got doubt when i am converting negative hexadecimal to a decimal number.Please look at mentioned example below. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.