Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

combining digits and leading zeros

Status
Not open for further replies.

underthewood

Programmer
Nov 8, 2010
4
Hey, I was wondering if I could get some help with the following. I have 2 seperate tet files listing columns of the same data but in a different format. Here's an example of how the same data is displayed in each file:

SINGLE COLUMN

v1v2v3

000
001
011
111

THREE SEPERATE COLUMNS

v1 v2 v3

0 0 0
0 0 1
0 1 1
1 1 1

So in the single column regime three digits make up a number, and in the second file three seperate integers are displayed, which correspond to the same order of the digits in the other file.

Now I can do one of two options. I can either seperate out the the digits in the first file into 3 columns, or I can combine the integers in the second file, just so I can get both in the same format.

Ive already attempted to do the latter method, by having something like VT= (100*v1)+(10*v2)+v3. The only problem with this is that if I have VT as an integer type, any preceding zeros I should have are ignored, and i need it in the v1v2v3 format (ie no double precision either).
How do I remedy this, or, alternatively is the other method easier?

Also, there are only ever 3 digits, which may be worth you knowing.

Cheers
Dan
 
I don't understand the reason why you say that any preceding zero is ignored.

Indeed, your formula is a bijection :

VT=(100*v1)+(10*v2)+v3

v1=VT/100
v2=(VT-100*v1)/10
v3=VT-100*v1-10*v2

If you want to print VT into a file, keeping exactly 3 digits, then the number format you need is "(I3.3)"

François Jacq
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top