PDA

View Full Version : numerical types

jrem
11-21-2009, 04:29 AM
Folks, I'm pulling my hair out on this one. I'm understanding that the default numerical values are DEC, but when I use a DEC value in LOOKUP (my lookup values are hex) I get jibberish.

My code is something like this:

tempx=50
digit_a=tempx.NIB0
digit_b=tempx.NIB1
LOOKUP digit_a, [\$00, \$00, \$e6, \$fe, \$e0, \$3e, \$b6, \$66, \$f4, \$dc, \$60, \$fa], pattern_a
LOOKUP digit_b, [\$00, \$00, \$e6, \$fe, \$e0, \$3e, \$b6, \$66, \$f4, \$dc, \$60, \$fa], pattern_b

I expect pattern_a to be \$00 and pattern_b to be \$e0, but it doesn't appear work out.

Any clues? Thanks . . .

Mike Green
11-21-2009, 05:12 AM
"50" is written as a decimal number. In binary, this is written as "%00110010". In hexadecimal, this is written as "\$32". Inside the Stamp, it's just a number.

NIB0 takes the least significant 4 bits of the number. In your case, this is a two. The LOOKUP will produce \$e6 for this.

NIB1 takes the most significant 4 bits of the number. In your case, this is a three. The LOOKUP will produce \$fe for this.

SRLM
11-21-2009, 05:13 AM
Look at the value of 50 (in decimal) in binary. It is 110010. So, the lower nib is 0010, or 2. The upper nib is 0011, or 3. Therefore, you should see pattern_a equal to \$e6 and pattern_b equal to \$fe.

edit: vroom through the submission button, Mike... :)

jrem
11-21-2009, 05:25 AM
yeah, I was afraid of that. The program isn't that difficult, so if I have to do the whole thing in hex I could have rehashed PIC code from other projects and just developed the whole think in the MPLAP IDE. The idea was to speed up development using the BS2, I was hoping it would do the conversions for me :(

SRLM
11-21-2009, 06:10 AM
Well, it can't read your mind. Just like the hex numbers in the lookup table, you have to tell the compiler that 50 is a hex number. It assumes that if you don't mention a base that you mean base 10. Just add a \$ in front.

jrem
11-21-2009, 06:24 AM
yeah, got that, but that's not what I was expecting. I was expecting the interpreter to do the math, i.e., if my number has no prefix (DEC) then it's decimal, if it has \$ then it's hex, and let the interpreter do the conversions. Else I'm doing all the conversions, so what's the point?

SRLM
11-21-2009, 07:53 AM
What do you mean? That is exactly what I said before. To expand, all numbers in a computer are stored in binary. There is absolutely nothing unique about that. The compiler on the computer will convert all the constants into binary, while the interpreter onboard the BS2 only works in binary and simply uses the various formatters to dictate how to interpret incoming data and format outgoing data.

jrem
11-21-2009, 08:13 AM
yeah, I got it the first time round, so no need to expand.