Printing float's to the console

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.
jox
Bug Slayer
Posts: 726
Joined: Thu Apr 22, 2004 6:55 pm
Location: Germany

Post by jox »

@Tyn:
mhh, I wonder who they are? :)

Ok, let's get you even more confused! :) (really hopefully taking away the confusion)

It's definitely not "a Hex represented as a decimal"

It's more the other way round, believe me!

You are coding/representing decimals! In binary. And then you can look at it in hex if you want...

But the hexadecimal aspect is not that relevant. But there's a phenomenon: The hexadecimal representation of a packed BCD looks exactly like the decimal (see the examples below). (each decimal digit is coded in a hexadecimal nibble)

You really should carefully read the article that warui posted:

http://www.danbbs.dk/~erikoest/bcd.htm
Tyn wrote: They store it in 4 bits per unit as the maximum figure will be 15
Wrong! The maximum figure is 9. BCD is actually wasting some bits (also in the packed BCD)! You won't see any A/B/C/D/E/F (binary 1010 to 1111) in a hex representation of a BCD!

here two examples:

111 (decimal)
00000001 00000001 00000001 (BCD (binary representation))
0001 0001 0001 (PACKED BCD (binary representation))
0x0111 (PACKED BCD (hexadecimal representation))

5639 (decimal)
00000101 00000110 00000011 00001001 (BCD (binary representation))
0101 0110 0011 1001 (PACKED BCD (binary representation))
0x5639 (PACKED BCD (hexadecimal representation))

hope this helps
Tyn
Posts: 932
Joined: Thu Nov 20, 2003 7:53 pm
Location: England
Contact:

Post by Tyn »

mhh, I wonder who they are?
The manufaturer of the unit I am using. They were basically salesmen. They had it explained to them by a group of German programmers who made the ladder programming software that goes with it, unfortunatly German apps tend to be very poor ( in my experience, I've seen about 4-5 German programs and 2-3 British and American programs ). Badly documented, badly translated, badly laid out and just plain poor. The help files are non-sensical and the system makes it hard to tell whether you are using BCD or binary. When you misunderstand what a BCD even IS then you start to have problems.

Well, we have finished with using that unit for a month or two so maybe I can come to it fresh and get someone to explain it over again. Apparently the company is offering a training course that will cover all this kind of stuff for a nominal fee so maybe I will get sent on it. As you can probably tell, I don't like dealing with things on a bit level. I have a fairly good grasp of Binary, I understand what Hex is, have heard about Oct but never had to use it and thought I knew what BCD was. Seems I am mistaken :) Hopefully with some practice I can understand it a little better.
jox
Bug Slayer
Posts: 726
Joined: Thu Apr 22, 2004 6:55 pm
Location: Germany

Post by jox »

heheh, you had it explained by some salesman who themselfs got it explained by some poor german programmers? :lol:
Electron
Posts: 874
Joined: Sun Mar 14, 2004 12:05 am
Location: Massachusetts USA

Post by Electron »

Note that I said a really stupid thing in my post. I said 6F hex= 0110 1111 which is BCH (binary coded hexadecimal) not BCD. As I think everone's figured out by now 6F is 111 decimel which is 0001 0001 0001 BCD
Sorry for my stupidity :oops:
You do a lot of programming? Really? I try to get some in, but the debugging keeps me pretty busy.

Crucible of Stars
Tyn
Posts: 932
Joined: Thu Nov 20, 2003 7:53 pm
Location: England
Contact:

Post by Tyn »

Totally, I asked today and someone gave me an answer ( whether it's right or not I don't know ).

They basically said that a BCD number in Hex is the same, but a hex is not always a BCD. BCD doesn't store any of the A-F numbers, only 0-9. That means that 6F as a BCD doesn't exist. So:

If you had a BCD of, say 16.

___1_______6
0001____0110

It reads the 1 and the 6 as two seperate numbers rather than two numbers put together. The actual decimal is 10110, or 22. To prove that the BCD number is the same as the Hex number, try converting 22 to a Hex. It will come out as a 16. This means doing math in BCD is pretty hard but luckly I probably won't have to do this. I can now convert from BCD to decimal using the BCD as if it were a hex which is all I needed. I wouldn't have bothered to find out if you guys hadn't questioned the method I thought I knew, thats for that.

I think I can convert backwards but I have to be careful that what I convert back doesn't equal a hex with an A-F digit in there or it will screw up :)

Like I said before, I'd rather be confused than believe something was right when it was wrong.
Post Reply