Reply by AlD February 9, 20102010-02-09
Here is the code I wrote to do the swap. Swap the upper four bits with
the lower four bitsof accumulator A, if byte is negative. I treated the
decimal data as "code" and manipulated it as binary. Sorry, I couldn't
find the code tags to display the program.
org $800

ldx #block ; initializepointer
for loading data

ldy #swaped ; initializepointer for
storage location

loop ldaa 1,x+ ; loaddata

beq done ; check forend of
data

bmi swap ; swap the 4-MSbits
and 4-LSbits, if A isnegative

bra loop

swap tab ; Swap the upper
four bits with the lower fourbits of accumulator A.

lsld ; shift
register D left 4 times, so A and B shiftalso

lsld

lsld

lsld

staa 1,y+ ; storageof
swapped negative byte

bra loop

done swi

org $1000

block fcb 220,$a1,$3c,$da,$b5,27,$e4,$f2

fcb 0 ; end of data

swaped rmb 8

Thanks

--- In 6..., Bill Auerbach wrote:
>
> Can you enlighten us please and tell us what your solution
> was? Maybe we'll understand the problem better if we are able to see
> the solution.
>
> Bill
>
> > AlD writes on 02:28 PM 2/8/2010
> >Okay guys, got it, sometimes it takes a bit, pardon the pun. I
> >appreciate your help, my code works great, now one less thing to do.
> >Al
> >
> >--- In













































'





























































'


'



















Reply by Bill Auerbach February 8, 20102010-02-08
Can you enlighten us please and tell us what your solution
was? Maybe we'll understand the problem better if we are able to see
the solution.

Bill

> AlD writes on 02:28 PM 2/8/2010
>Okay guys, got it, sometimes it takes a bit, pardon the pun. I
>appreciate your help, my code works great, now one less thing to do.
>Al
>
>--- In












































'




























































'


'



















Reply by Angel Castillo February 8, 20102010-02-08
finally inside a computer all the numbers are binary
think your the hexadecimal or decimal according to your application and
convenience

or Perhaps you are confusing a number with one decimal BCD (Binary coded
decimal)
for example

1101 0011 is D3 hex number or 211 decimal but is not BCD number

or

1001 0011 is 93 hex number or 147 decimal number or 93 BCD number

2010/2/8 AlD

> I'm writing a program that will swap the most significant 4-bits with the
> least significant 4 bits of only the negative bytes of a block of 8 bytes.
> The numbers in the block are a mix of decimal and hex numbers. The only
> problem I'm having is determining whether a positive decimal number is
> positive. As an example the decimal number 220 is 11011100. If I test bit 7
> it will show 220 as a negative number, when in fact it is positive. How
> would I test a decimal number for being positive or for being negative if
> that is easier?
> Thanks
>
>
Reply by AlD February 8, 20102010-02-08
Okay guys, got it, sometimes it takes a bit, pardon the pun. I appreciate your help, my code works great, now one less thing to do.
Al

--- In 6..., "Anders Friberg" wrote:
>
> Just look at "220" as a code, it is always stored in the hardware as a group
> of 8 bits 11011100.
>
> The strings "220", "$dc" or "11011100b" are just different text format in
> the source code, they give the same code.
>
>
> > -----Original Message-----
> > From: 6... [mailto:6...]
> > On Behalf Of AlD
> > Sent: Monday, February 08, 2010 7:49 PM
> > To: 6...
> > Subject: [68HC12] Re: Determining sign of decmial number
> >
> >
> >
> > Emmett, Anders and Joel
> >
> > Thanks for the input,I understand what you are saying, but as
> > Anders puts it so well, "someone is trying to fool someone."
> > I have to deal with the sequence given:
> > 220,$a1,$3c,$da,$b5,27,$e4,$f2. Is there a way to detect that
> > 220 is a positive decimal number and bypass it, a way to
> > detect the number base prefix? If the data is in hex I can go
> > test it for negative or positive and do the swap?
> >
> > --- In 6..., "Redd, Emmett R"
> > wrote:
> > >
> > > Al,
> > >
> > > Joel gave you a long and detailed and I gave you a short
> > one. My answer implied that you have to decide what number
> > you want a byte to represent. Joel was more direct, "YOU
> > decide what means the number in you[r] system".
> > >
> > > Once you decide you need signed numbers, the most
> > significant bit of the byte is the sign and you are limited
> > to -128 to 127 decimal ($80 to $ff, $00 to $7f in
> > hexadecimal). You can't have 220 decimal ($dc hexadecimal)
> > and have signed numbers represented in a byte.
> > >
> > > So, what do you choose: larger unsigned numbers or smaller
> > signed numbers?
> > >
> > > Emmett Redd, Ph.D., Professor mailto:EmmettRedd@
> > > Physics, Astronomy, and Materials Science Office: 417-836-5221
> > > Missouri State University Dept: 417-838-5131
> > > 901 S NATIONAL AVENUE FAX: 417-836-6226
> > > SPRINGFIELD, MO 65897 USA
> > >
> > >
> > >
> > > -----Original Message-----
> > > From: 6...
> > [mailto:6...] On Behalf Of AlD
> > > Sent: Monday, February 08, 2010 11:37 AM
> > > To: 6...
> > > Subject: [68HC12] Re: Determining sign of decmial number
> > >
> > >
> > >
> > >
> > >
> > >
> > > Right, but how would I determine whether the number is
> > decimal or hex number. If it were a decimal I could assume it
> > was a positive number. I guess the decimal number could be
> > decimal -27, which could be represented by 8 bit number?
> > Example number sequence, 220,$a1,$3c,$da,$b5,27,$e4,$f2.
> > Thanks for the help.
> > >
> > > --- In 6..., "Redd, Emmett R" wrote:
> > > >
> > > > If 11011100 is 220 decimal, then there are no 8-bit bytes
> > that can represent a negative number; a byte can represent
> > the decimal range from 0 to 255 or from -128 to 127 but not both.
> > > >
> > > > Emmett Redd Ph.D. mailto:EmmettRedd@
> > > > Professor (417)836-5221
> > > > Department of Physics, Astronomy, and Materials Science
> > > > Missouri State University Fax (417)836-6226
> > > > 901 SOUTH NATIONAL Lab (417)836-3770
> > > > SPRINGFIELD, MO 65897 USA Dept (417)836-5131
> > > >
> > > > "In theory there is no difference between theory and
> > practice. In practice there is." -- Yogi Berra or Jan van de
> > Snepscheut
> > > >
> > > > ________________________________________
> > > > From: 6... [6...] On
> > Behalf Of AlD [al_delgado@]
> > > > Sent: Monday, February 08, 2010 12:55 AM
> > > > To: 6...
> > > > Subject: [68HC12] Determining sign of decmial number
> > > >
> > > > I'm writing a program that will swap the most significant
> > 4-bits with the least significant 4 bits of only the negative
> > bytes of a block of 8 bytes. The numbers in the block are a
> > mix of decimal and hex numbers. The only problem I'm having
> > is determining whether a positive decimal number is positive.
> > As an example the decimal number 220 is 11011100. If I test
> > bit 7 it will show 220 as a negative number, when in fact it
> > is positive. How would I test a decimal number for being
> > positive or for being negative if that is easier?
> > > > Thanks
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
Reply by Anders Friberg February 8, 20102010-02-08
Just look at "220" as a code, it is always stored in the hardware as a group
of 8 bits 11011100.

The strings "220", "$dc" or "11011100b" are just different text format in
the source code, they give the same code.

> -----Original Message-----
> From: 6... [mailto:6...]
> On Behalf Of AlD
> Sent: Monday, February 08, 2010 7:49 PM
> To: 6...
> Subject: [68HC12] Re: Determining sign of decmial number
>
> Emmett, Anders and Joel
>
> Thanks for the input,I understand what you are saying, but as
> Anders puts it so well, "someone is trying to fool someone."
> I have to deal with the sequence given:
> 220,$a1,$3c,$da,$b5,27,$e4,$f2. Is there a way to detect that
> 220 is a positive decimal number and bypass it, a way to
> detect the number base prefix? If the data is in hex I can go
> test it for negative or positive and do the swap?
>
> --- In 6..., "Redd, Emmett R"
> wrote:
> >
> > Al,
> >
> > Joel gave you a long and detailed and I gave you a short
> one. My answer implied that you have to decide what number
> you want a byte to represent. Joel was more direct, "YOU
> decide what means the number in you[r] system".
> >
> > Once you decide you need signed numbers, the most
> significant bit of the byte is the sign and you are limited
> to -128 to 127 decimal ($80 to $ff, $00 to $7f in
> hexadecimal). You can't have 220 decimal ($dc hexadecimal)
> and have signed numbers represented in a byte.
> >
> > So, what do you choose: larger unsigned numbers or smaller
> signed numbers?
> >
> > Emmett Redd, Ph.D., Professor mailto:EmmettRedd@...
> > Physics, Astronomy, and Materials Science Office: 417-836-5221
> > Missouri State University Dept: 417-838-5131
> > 901 S NATIONAL AVENUE FAX: 417-836-6226
> > SPRINGFIELD, MO 65897 USA
> >
> >
> >
> > -----Original Message-----
> > From: 6...
> [mailto:6...] On Behalf Of AlD
> > Sent: Monday, February 08, 2010 11:37 AM
> > To: 6...
> > Subject: [68HC12] Re: Determining sign of decmial number
> >
> >
> >
> >
> >
> >
> > Right, but how would I determine whether the number is
> decimal or hex number. If it were a decimal I could assume it
> was a positive number. I guess the decimal number could be
> decimal -27, which could be represented by 8 bit number?
> Example number sequence, 220,$a1,$3c,$da,$b5,27,$e4,$f2.
> Thanks for the help.
> >
> > --- In 6..., "Redd, Emmett R" wrote:
> > >
> > > If 11011100 is 220 decimal, then there are no 8-bit bytes
> that can represent a negative number; a byte can represent
> the decimal range from 0 to 255 or from -128 to 127 but not both.
> > >
> > > Emmett Redd Ph.D. mailto:EmmettRedd@
> > > Professor (417)836-5221
> > > Department of Physics, Astronomy, and Materials Science
> > > Missouri State University Fax (417)836-6226
> > > 901 SOUTH NATIONAL Lab (417)836-3770
> > > SPRINGFIELD, MO 65897 USA Dept (417)836-5131
> > >
> > > "In theory there is no difference between theory and
> practice. In practice there is." -- Yogi Berra or Jan van de
> Snepscheut
> > >
> > > ________________________________________
> > > From: 6... [6...] On
> Behalf Of AlD [al_delgado@]
> > > Sent: Monday, February 08, 2010 12:55 AM
> > > To: 6...
> > > Subject: [68HC12] Determining sign of decmial number
> > >
> > > I'm writing a program that will swap the most significant
> 4-bits with the least significant 4 bits of only the negative
> bytes of a block of 8 bytes. The numbers in the block are a
> mix of decimal and hex numbers. The only problem I'm having
> is determining whether a positive decimal number is positive.
> As an example the decimal number 220 is 11011100. If I test
> bit 7 it will show 220 as a negative number, when in fact it
> is positive. How would I test a decimal number for being
> positive or for being negative if that is easier?
> > > Thanks
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> >
> >
> >
> >
> >
> >
> >
Reply by "Redd, Emmett R" February 8, 20102010-02-08
Al,

Since you agree that the teacher decides, perhaps he is asking a different question than what you are presenting here. Perhaps he is really testing your understanding. From the response immediately, you simply still do not "understand". We have been telling you that it is impossible to answer the question as you have it; please reread all of our posts carefully. When you really understand what we have written, take you understanding to your teacher and tell him that it is impossible to do. Have him help you clear up what he is really asking you.

Emmett Redd, Ph.D., Professor mailto:E...@MissouriState.Edu
Physics, Astronomy, and Materials Science Office: 417-836-5221
Missouri State University Dept: 417-838-5131
901 S NATIONAL AVENUE FAX: 417-836-6226
SPRINGFIELD, MO 65897 USA

-----Original Message-----
From: 6... [mailto:6...] On Behalf Of AlD
Sent: Monday, February 08, 2010 12:49 PM
To: 6...
Subject: [68HC12] Re: Determining sign of decmial number

Emmett, Anders and Joel

Thanks for the input,I understand what you are saying, but as Anders puts it so well, "someone is trying to fool someone." I have to deal with the sequence given: 220,$a1,$3c,$da,$b5,27,$e4,$f2. Is there a way to detect that 220 is a positive decimal number and bypass it, a way to detect the number base prefix? If the data is in hex I can go test it for negative or positive and do the swap?

--- In 6..., "Redd, Emmett R" wrote:
>
> Al,
>
> Joel gave you a long and detailed and I gave you a short one. My answer implied that you have to decide what number you want a byte to represent. Joel was more direct, "YOU decide what means the number in you[r] system".
>
> Once you decide you need signed numbers, the most significant bit of the byte is the sign and you are limited to -128 to 127 decimal ($80 to $ff, $00 to $7f in hexadecimal). You can't have 220 decimal ($dc hexadecimal) and have signed numbers represented in a byte.
>
> So, what do you choose: larger unsigned numbers or smaller signed numbers?
>
> Emmett Redd, Ph.D., Professor mailto:EmmettRedd@...
> Physics, Astronomy, and Materials Science Office: 417-836-5221
> Missouri State University Dept: 417-838-5131
> 901 S NATIONAL AVENUE FAX: 417-836-6226
> SPRINGFIELD, MO 65897 USA
>
> -----Original Message-----
> From: 6... [mailto:6...] On Behalf Of AlD
> Sent: Monday, February 08, 2010 11:37 AM
> To: 6...
> Subject: [68HC12] Re: Determining sign of decmial number
> Right, but how would I determine whether the number is decimal or hex number. If it were a decimal I could assume it was a positive number. I guess the decimal number could be decimal -27, which could be represented by 8 bit number? Example number sequence, 220,$a1,$3c,$da,$b5,27,$e4,$f2. Thanks for the help.
>
> --- In 6..., "Redd, Emmett R" wrote:
> >
> > If 11011100 is 220 decimal, then there are no 8-bit bytes that can represent a negative number; a byte can represent the decimal range from 0 to 255 or from -128 to 127 but not both.
> >
> > Emmett Redd Ph.D. mailto:EmmettRedd@
> > Professor (417)836-5221
> > Department of Physics, Astronomy, and Materials Science
> > Missouri State University Fax (417)836-6226
> > 901 SOUTH NATIONAL Lab (417)836-3770
> > SPRINGFIELD, MO 65897 USA Dept (417)836-5131
> >
> > "In theory there is no difference between theory and practice. In practice there is." -- Yogi Berra or Jan van de Snepscheut
> >
> > ________________________________________
> > From: 6... [6...] On Behalf Of AlD [al_delgado@]
> > Sent: Monday, February 08, 2010 12:55 AM
> > To: 6...
> > Subject: [68HC12] Determining sign of decmial number
> >
> > I'm writing a program that will swap the most significant 4-bits with the least significant 4 bits of only the negative bytes of a block of 8 bytes. The numbers in the block are a mix of decimal and hex numbers. The only problem I'm having is determining whether a positive decimal number is positive. As an example the decimal number 220 is 11011100. If I test bit 7 it will show 220 as a negative number, when in fact it is positive. How would I test a decimal number for being positive or for being negative if that is easier?
> > Thanks
> >
> >
> >
> >
> >
> >
> >
>
Reply by AlD February 8, 20102010-02-08
yep

--- In 6..., "Anders Friberg" wrote:
>
> You mean the *teacher* decides? :)
>
> > -----Original Message-----
> > From: 6... [mailto:6...]
> > On Behalf Of Redd, Emmett R
> > Sent: Monday, February 08, 2010 7:29 PM
> > To: 6...
> > Subject: RE: [68HC12] Re: Determining sign of decmial number
> >
> > Al,
> >
> > Joel gave you a long and detailed and I gave you a short one.
> > My answer implied that you have to decide what number you
> > want a byte to represent. Joel was more direct, "YOU decide
> > what means the number in you[r] system".
> >
> > Once you decide you need signed numbers, the most significant
> > bit of the byte is the sign and you are limited to -128 to
> > 127 decimal ($80 to $ff, $00 to $7f in hexadecimal). You
> > can't have 220 decimal ($dc hexadecimal) and have signed
> > numbers represented in a byte.
> >
> > So, what do you choose: larger unsigned numbers or smaller
> > signed numbers?
> >
> > Emmett Redd, Ph.D., Professor mailto:EmmettRedd@...
> > Physics, Astronomy, and Materials Science Office: 417-836-5221
> > Missouri State University Dept: 417-838-5131
> > 901 S NATIONAL AVENUE FAX: 417-836-6226
> > SPRINGFIELD, MO 65897 USA
> >
> >
> >
> > -----Original Message-----
> > From: 6... [mailto:6...]
> > On Behalf Of AlD
> > Sent: Monday, February 08, 2010 11:37 AM
> > To: 6...
> > Subject: [68HC12] Re: Determining sign of decmial number
> >
> >
> >
> >
> >
> >
> > Right, but how would I determine whether the number is
> > decimal or hex number. If it were a decimal I could assume it
> > was a positive number. I guess the decimal number could be
> > decimal -27, which could be represented by 8 bit number?
> > Example number sequence, 220,$a1,$3c,$da,$b5,27,$e4,$f2.
> > Thanks for the help.
> >
> > --- In 6..., "Redd, Emmett R"
> > wrote:
> > >
> > > If 11011100 is 220 decimal, then there are no 8-bit bytes
> > that can represent a negative number; a byte can represent
> > the decimal range from 0 to 255 or from -128 to 127 but not both.
> > >
> > > Emmett Redd Ph.D. mailto:EmmettRedd@
> > > Professor (417)836-5221
> > > Department of Physics, Astronomy, and Materials Science
> > > Missouri State University Fax (417)836-6226
> > > 901 SOUTH NATIONAL Lab (417)836-3770
> > > SPRINGFIELD, MO 65897 USA Dept (417)836-5131
> > >
> > > "In theory there is no difference between theory and
> > practice. In practice there is." -- Yogi Berra or Jan van de
> > Snepscheut
> > >
> > > ________________________________________
> > > From: 6... [6...] On
> > Behalf Of AlD [al_delgado@]
> > > Sent: Monday, February 08, 2010 12:55 AM
> > > To: 6...
> > > Subject: [68HC12] Determining sign of decmial number
> > >
> > > I'm writing a program that will swap the most significant
> > 4-bits with the least significant 4 bits of only the negative
> > bytes of a block of 8 bytes. The numbers in the block are a
> > mix of decimal and hex numbers. The only problem I'm having
> > is determining whether a positive decimal number is positive.
> > As an example the decimal number 220 is 11011100. If I test
> > bit 7 it will show 220 as a negative number, when in fact it
> > is positive. How would I test a decimal number for being
> > positive or for being negative if that is easier?
> > > Thanks
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> >
> >
> >
> >
> >
> >
> >
Reply by AlD February 8, 20102010-02-08
Emmett, Anders and Joel

Thanks for the input,I understand what you are saying, but as Anders puts it so well, "someone is trying to fool someone." I have to deal with the sequence given: 220,$a1,$3c,$da,$b5,27,$e4,$f2. Is there a way to detect that 220 is a positive decimal number and bypass it, a way to detect the number base prefix? If the data is in hex I can go test it for negative or positive and do the swap?

--- In 6..., "Redd, Emmett R" wrote:
>
> Al,
>
> Joel gave you a long and detailed and I gave you a short one. My answer implied that you have to decide what number you want a byte to represent. Joel was more direct, "YOU decide what means the number in you[r] system".
>
> Once you decide you need signed numbers, the most significant bit of the byte is the sign and you are limited to -128 to 127 decimal ($80 to $ff, $00 to $7f in hexadecimal). You can't have 220 decimal ($dc hexadecimal) and have signed numbers represented in a byte.
>
> So, what do you choose: larger unsigned numbers or smaller signed numbers?
>
> Emmett Redd, Ph.D., Professor mailto:EmmettRedd@...
> Physics, Astronomy, and Materials Science Office: 417-836-5221
> Missouri State University Dept: 417-838-5131
> 901 S NATIONAL AVENUE FAX: 417-836-6226
> SPRINGFIELD, MO 65897 USA
>
> -----Original Message-----
> From: 6... [mailto:6...] On Behalf Of AlD
> Sent: Monday, February 08, 2010 11:37 AM
> To: 6...
> Subject: [68HC12] Re: Determining sign of decmial number
> Right, but how would I determine whether the number is decimal or hex number. If it were a decimal I could assume it was a positive number. I guess the decimal number could be decimal -27, which could be represented by 8 bit number? Example number sequence, 220,$a1,$3c,$da,$b5,27,$e4,$f2. Thanks for the help.
>
> --- In 6..., "Redd, Emmett R" wrote:
> >
> > If 11011100 is 220 decimal, then there are no 8-bit bytes that can represent a negative number; a byte can represent the decimal range from 0 to 255 or from -128 to 127 but not both.
> >
> > Emmett Redd Ph.D. mailto:EmmettRedd@
> > Professor (417)836-5221
> > Department of Physics, Astronomy, and Materials Science
> > Missouri State University Fax (417)836-6226
> > 901 SOUTH NATIONAL Lab (417)836-3770
> > SPRINGFIELD, MO 65897 USA Dept (417)836-5131
> >
> > "In theory there is no difference between theory and practice. In practice there is." -- Yogi Berra or Jan van de Snepscheut
> >
> > ________________________________________
> > From: 6... [6...] On Behalf Of AlD [al_delgado@]
> > Sent: Monday, February 08, 2010 12:55 AM
> > To: 6...
> > Subject: [68HC12] Determining sign of decmial number
> >
> > I'm writing a program that will swap the most significant 4-bits with the least significant 4 bits of only the negative bytes of a block of 8 bytes. The numbers in the block are a mix of decimal and hex numbers. The only problem I'm having is determining whether a positive decimal number is positive. As an example the decimal number 220 is 11011100. If I test bit 7 it will show 220 as a negative number, when in fact it is positive. How would I test a decimal number for being positive or for being negative if that is easier?
> > Thanks
> >
> >
> >
> >
> >
> >
> >
>
Reply by Anders Friberg February 8, 20102010-02-08
You mean the *teacher* decides? :)

> -----Original Message-----
> From: 6... [mailto:6...]
> On Behalf Of Redd, Emmett R
> Sent: Monday, February 08, 2010 7:29 PM
> To: 6...
> Subject: RE: [68HC12] Re: Determining sign of decmial number
>
> Al,
>
> Joel gave you a long and detailed and I gave you a short one.
> My answer implied that you have to decide what number you
> want a byte to represent. Joel was more direct, "YOU decide
> what means the number in you[r] system".
>
> Once you decide you need signed numbers, the most significant
> bit of the byte is the sign and you are limited to -128 to
> 127 decimal ($80 to $ff, $00 to $7f in hexadecimal). You
> can't have 220 decimal ($dc hexadecimal) and have signed
> numbers represented in a byte.
>
> So, what do you choose: larger unsigned numbers or smaller
> signed numbers?
>
> Emmett Redd, Ph.D., Professor mailto:E...@MissouriState.Edu
> Physics, Astronomy, and Materials Science Office: 417-836-5221
> Missouri State University Dept: 417-838-5131
> 901 S NATIONAL AVENUE FAX: 417-836-6226
> SPRINGFIELD, MO 65897 USA
>
> -----Original Message-----
> From: 6... [mailto:6...]
> On Behalf Of AlD
> Sent: Monday, February 08, 2010 11:37 AM
> To: 6...
> Subject: [68HC12] Re: Determining sign of decmial number
> Right, but how would I determine whether the number is
> decimal or hex number. If it were a decimal I could assume it
> was a positive number. I guess the decimal number could be
> decimal -27, which could be represented by 8 bit number?
> Example number sequence, 220,$a1,$3c,$da,$b5,27,$e4,$f2.
> Thanks for the help.
>
> --- In 6..., "Redd, Emmett R"
> wrote:
> >
> > If 11011100 is 220 decimal, then there are no 8-bit bytes
> that can represent a negative number; a byte can represent
> the decimal range from 0 to 255 or from -128 to 127 but not both.
> >
> > Emmett Redd Ph.D. mailto:EmmettRedd@...
> > Professor (417)836-5221
> > Department of Physics, Astronomy, and Materials Science
> > Missouri State University Fax (417)836-6226
> > 901 SOUTH NATIONAL Lab (417)836-3770
> > SPRINGFIELD, MO 65897 USA Dept (417)836-5131
> >
> > "In theory there is no difference between theory and
> practice. In practice there is." -- Yogi Berra or Jan van de
> Snepscheut
> >
> > ________________________________________
> > From: 6... [6...] On
> Behalf Of AlD [al_delgado@...]
> > Sent: Monday, February 08, 2010 12:55 AM
> > To: 6...
> > Subject: [68HC12] Determining sign of decmial number
> >
> > I'm writing a program that will swap the most significant
> 4-bits with the least significant 4 bits of only the negative
> bytes of a block of 8 bytes. The numbers in the block are a
> mix of decimal and hex numbers. The only problem I'm having
> is determining whether a positive decimal number is positive.
> As an example the decimal number 220 is 11011100. If I test
> bit 7 it will show 220 as a negative number, when in fact it
> is positive. How would I test a decimal number for being
> positive or for being negative if that is easier?
> > Thanks
> >
> >
> >
> >
> >
> >
> >
>
Reply by "Redd, Emmett R" February 8, 20102010-02-08
Al,

Joel gave you a long and detailed and I gave you a short one. My answer implied that you have to decide what number you want a byte to represent. Joel was more direct, "YOU decide what means the number in you[r] system".

Once you decide you need signed numbers, the most significant bit of the byte is the sign and you are limited to -128 to 127 decimal ($80 to $ff, $00 to $7f in hexadecimal). You can't have 220 decimal ($dc hexadecimal) and have signed numbers represented in a byte.

So, what do you choose: larger unsigned numbers or smaller signed numbers?

Emmett Redd, Ph.D., Professor mailto:E...@MissouriState.Edu
Physics, Astronomy, and Materials Science Office: 417-836-5221
Missouri State University Dept: 417-838-5131
901 S NATIONAL AVENUE FAX: 417-836-6226
SPRINGFIELD, MO 65897 USA

-----Original Message-----
From: 6... [mailto:6...] On Behalf Of AlD
Sent: Monday, February 08, 2010 11:37 AM
To: 6...
Subject: [68HC12] Re: Determining sign of decmial number

Right, but how would I determine whether the number is decimal or hex number. If it were a decimal I could assume it was a positive number. I guess the decimal number could be decimal -27, which could be represented by 8 bit number? Example number sequence, 220,$a1,$3c,$da,$b5,27,$e4,$f2. Thanks for the help.

--- In 6..., "Redd, Emmett R" wrote:
>
> If 11011100 is 220 decimal, then there are no 8-bit bytes that can represent a negative number; a byte can represent the decimal range from 0 to 255 or from -128 to 127 but not both.
>
> Emmett Redd Ph.D. mailto:EmmettRedd@...
> Professor (417)836-5221
> Department of Physics, Astronomy, and Materials Science
> Missouri State University Fax (417)836-6226
> 901 SOUTH NATIONAL Lab (417)836-3770
> SPRINGFIELD, MO 65897 USA Dept (417)836-5131
>
> "In theory there is no difference between theory and practice. In practice there is." -- Yogi Berra or Jan van de Snepscheut
>
> ________________________________________
> From: 6... [6...] On Behalf Of AlD [al_delgado@...]
> Sent: Monday, February 08, 2010 12:55 AM
> To: 6...
> Subject: [68HC12] Determining sign of decmial number
>
> I'm writing a program that will swap the most significant 4-bits with the least significant 4 bits of only the negative bytes of a block of 8 bytes. The numbers in the block are a mix of decimal and hex numbers. The only problem I'm having is determining whether a positive decimal number is positive. As an example the decimal number 220 is 11011100. If I test bit 7 it will show 220 as a negative number, when in fact it is positive. How would I test a decimal number for being positive or for being negative if that is easier?
> Thanks
>
>
>