The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum
 Origin Forum
 Converting Hex to Dec and vice versa
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

MingliFu

10 Posts

Posted - 02/08/2010 :  04:17:14 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hello together,

could some1 of you tell me how to convert a normal decimal value in coloum A in a hex-value in coloum B and the other way?

For example:

A B
0 0
1 1
2 2
3 3
9 9
10 A
11 B
12 C

Have i to write a LabTalk function or is there a easier way to solve this problem!?!!

THX a lot!!!!
MINGLIFU

MingliFu

10 Posts

Posted - 02/08/2010 :  06:49:02 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
noone?
Go to Top of Page

rlewis

Canada
253 Posts

Posted - 02/08/2010 :  6:20:52 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
It should be relatively easy to code such a function with OriginC ..
WHy not give it a try ...
Go to Top of Page

MingliFu

10 Posts

Posted - 02/11/2010 :  03:24:19 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Please!
Help me!!

Go to Top of Page

larry_lan

China
Posts

Posted - 02/11/2010 :  05:12:10 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi:

For example, you can write an Origin C function to convert Dec to Hex:

string Dec2Hex(int a)
{
	string strHexA;
	strHexA.Format("%p", a);
	strHexA.TrimLeft('0');
	return strHexA;
}

Then in Set Column Values dialog, say col(a) is Dec and you want to convert to Hex in col(b), you can set:

col(b) = Dec2Hex(col(a))$

Please read more information from Origin Programming Guide, and you can also search the function Hex2Dec in Origin C help.

Thanks
Larry
OriginLab Technical Services

Edited by - larry_lan on 02/11/2010 05:13:23 AM
Go to Top of Page

MingliFu

10 Posts

Posted - 02/11/2010 :  06:10:19 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi larry_lan,

i wrote this func in "CodeBuilder".
Compiled and created it.
If i go now to col(b) and "Fill Coloum with Values" and i wrote
"Dec2Hex(col(a))$" but there are just "-" Symbols.
like this:
A B
0 -
1 -
2 -
3 -
4 -
5 -
6 -

Please help me!
And sorry for my bad english!

MingliFu
Go to Top of Page

larry_lan

China
Posts

Posted - 02/11/2010 :  07:34:31 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
What's your Origin version? If it's not the latest Origin, please download the demo version from our website and have a try. You can contact your local distributor to update your Origin.

Thanks
Larry

Edited by - larry_lan on 02/11/2010 07:36:03 AM
Go to Top of Page

MingliFu

10 Posts

Posted - 02/11/2010 :  2:34:37 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
7.5G
Go to Top of Page

Iris_Bai

China
Posts

Posted - 02/12/2010 :  01:33:37 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Origin7.5 does not support the usage in Set Column Value dialog yet.

We suggest you upgrade to newest Origin version 81, which contains many other improvements.

As to O75, please use the following function to call Larry's Dec2Hex function. Run "ConvertHelper(1, 2)" in script window.


void ConvertHelper(int nSourceColIndex, int nDestColIndex) // this index is 1 offset
{
	// The index offset is 0 in Origin C
	nSourceColIndex--;
	nDestColIndex--;
	
	Worksheet wks = Project.ActiveLayer();
	if( !wks || !wks.Columns(nSourceColIndex) || !wks.Columns(nDestColIndex) )
	{
		out_str("No acitve worksheet or input column is invalid");
		return;
	}
		
	Column colSource(wks, nSourceColIndex), colDest(wks, nDestColIndex);	
	Dataset dsSource(colSource), dsDest(colDest);
	vector<string> vsHex;
	for(int nn = 0; nn < dsSource.GetSize(); nn++)
	{
		string strHex = Dec2Hex(dsSource[nn]);
		vsHex.Add(strHex);
	}
	dsDest.PutStringArray(vsHex);	
}




Iris

Edited by - Iris_Bai on 02/12/2010 01:34:58 AM
Go to Top of Page

MingliFu

10 Posts

Posted - 02/12/2010 :  08:31:56 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Iris,

thx a lot to you!!!
It works!!

MingliFu
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000