Jump to content

Binary conversion in PCM


---
 Share

Recommended Posts

I was trying to do some complex calculations in pcm, instead of exporting data to an external program written in fortrun 200 years ago by some one who most likely are dead now. The only documentation available stated that calculation shall be done in binary due to precision issues in double with some of the math I cant access due to source code missing. (Well, that might not be true, but I don't really know what's going on in the external program. Only that it is used for strain and life length determination.)

And I really don't like to change the whole concept since it's proven to work for the last 40 years or so.
So what I needed was a way to convert binary to double, so once I sent the info to the program, calculations are done and all I get as a result is binary.

So as a "fun" challenge, How would you convert lets say: "111010110111100110100010101" and "00000111010110111100110100010101" back to "123456789". You are only allowed to use PCM.
Link to comment
Share on other sites

I'd rather shoot myself in the foot before I'd even think about trying something like this with PCM 🤣 🤣 🤣
I trust you haven't used any fancy 'undocumented' stuff? 😉
Link to comment
Share on other sites

Yeah, I kind of figured. It really falls out side of CMM programing, but can actually be helpful in some very limited fields. And I hoped that some one else was forced to do very weird stuff. 😉

Any way. This finally got me to understand why you cant assign variable names starting with a integer. A question I've asked everyone at Zeiss I ever met. But never got an answer to. So let me be the messenger, like Jesus if you wish.

It all ends up on how Arithmetic values are "read" in the software. Or numbers to be more specific.
And since there actually exist a radix function, the "first" number in a line is to tell what base it belongs to. Where 2 is binary. Since binary only contains 0 and 1. Two different numbers. 8 is octal 0 to 7. 10 is everyone familiar with, right? No? 0-9, yes the decimal system. 16 the Hex, and loads of more that I've never heard of...

Well so to convert the binary number of 111010110111100110100010101 we need to start to compare what number that's next to each other. So my very first rough approach was something like this:
string="111010110111100110100010101"
for i = 1 to string.capacity
	binContainer[i]=subStr(string,i,i).asInteger
next i

for i = 1 to string.capacity
	convert = 0
	j=i+1
	if i <> string.capacity
		if binContainer[j] < 0 or binContainer[j] == binContainer[i]
			convert = convert * binContainer[i] + binContainer[j]
		endif
	endif
next i
Some one might see where this is going.. But I stumbled upon something while storing temporary variables. Like:
abc=111010110111100110100010101
As you can see the value is not the same when recollected. That caused some, lets say "confusion".

While testing weird stuff I stumbled upon 666. That I know origins from 29a in the hex system. (Yeah, it was fun to play with calculators in school..)

So, the conclusion. Why cant you assign variables starting with integers? Cause leading integers tells the software what place-value notation that should be used. As I said before, 16 is hex, 2 is binary. And the "hidden" radix function I "stumbled" upon while receiving 666. is simply "r". So:
16r29a = 666
2r111010110111100110100010101 = 123456789
So this task that I tough would take weeks turned out to be really simple in the end.
So even if you don't care. You can now at least shine when someone ask why variables can't start with a integer. Or convert binary, Hex or what ever else you wish, stupidly simple.

And when Christmas arrives, remember me! I like expensive stuff 😃
Link to comment
Share on other sites

  • 5 months later...
  • 4 weeks later...

Please sign in to view this quote.

Eric. You were so kind to post an "un-zipped" format before. I hate to beg.... How about a windows zipped file instead of winzip? Or, am I asking too much?
Link to comment
Share on other sites

  • 5 months later...
  • 1 month later...
  • 3 weeks later...
  • 1 month later...

Please sign in to view this quote.

Hi guys

Looking for unsupported PCM syntax
This file is not avaiable anymore.
Can someone provide it ?

Thanks a million.
Link to comment
Share on other sites

 Share

×
×
  • Create New...