### Author Topic: Hex confusion: what value is attained when I decrement 0x00?  (Read 2926 times)

0 Members and 1 Guest are viewing this topic.

#### iamwhoiam

• Contributor
• Banned!
• Posts: 37
##### Hex confusion: what value is attained when I decrement 0x00?
« on: June 03, 2012, 04:07:58 pm »
Hi guys. Being used to decimal, naturally, I am confused by this; the part highlighted in red:

LED_PAUSE
MOVLW 0xFF
MOVWF LED_LOOP2

LED_PAUSE2
CLRF LED_LOOP
DECFSZ LED_LOOP,F
GOTO \$-1
DECFSZ LED_LOOP2,F
GOTO LED_PAUSE2

END

Seeing as "LED_LOOP" has been issued CLRF, and hence contains 0x00, what value does decrementing 0x00 result in; 0xFF?

Hex n00b!

Thanks.
« Last Edit: June 03, 2012, 04:11:06 pm by iamwhoiam »

#### MikeK

• Frequent Contributor
• Posts: 577
• Country:
##### Re: Hex confusion: what value is attained when I decrement 0x00?
« Reply #1 on: June 03, 2012, 04:14:49 pm »
The opposite of what happens when you increment 0xFF.

#### AntiProtonBoy

• Frequent Contributor
• Posts: 770
• Country:
##### Re: Hex confusion: what value is attained when I decrement 0x00?
« Reply #2 on: June 03, 2012, 04:42:06 pm »
Google says 0x00 -1 is -0x1...  or is that just Google fail?
Not necessarily a fail, it depends how the byte is interpreted.

If you interpret 11111111 as an unsigned binary, then its hex equivalent is 0xFF, or 255 decimal.
If you interpret 11111111 as a two's complement signed binary, then hex is -0x01, or -1 decimal.

That being said, hex constant values are generally interpreted as a raw collection of bits with the sign absent, thus I'd find the -0x01 notation unusual.

#### caroper

• Regular Contributor
• Posts: 193
• Country:
##### Re: Hex confusion: what value is attained when I decrement 0x00?
« Reply #3 on: June 03, 2012, 08:26:35 pm »
Thanks to binary arithmetic we have finally solved Shakespeare's famous  dilemma.

2B OR NOT 2B = -1

Cheers
Chris

#### Mechatrommer

• Super Contributor
• Posts: 9318
• Country:
• reassessing directives...
##### Re: Hex confusion: what value is attained when I decrement 0x00?
« Reply #4 on: June 04, 2012, 06:44:42 am »
Quote from: OP
what value is attained when I decrement 0x00?
The opposite of what happens when you increment 0xFF.
(its been a while). what value will depend on how many bits per byte/register we have and architecture of the "flipflop" (is it the right term?). deducted it to 8bit PIC8 (from your example).. my answer is 0xFF with 1 in carry (or zero) bit. incrementing  0xFF will result in 0x00 with 1 in carry/zero bit.
« Last Edit: June 04, 2012, 06:47:02 am by Mechatrommer »
if something can select, how cant it be intelligent? if something is intelligent, how cant it exist?

Smf