when I convert hex 513 double word to byte it's 1? 5634 is 2?

  • Follow


Sorry, I'm learning. Without casting I got 513 so I type casted it to
int8 and it's 1(which is what I wanted).  When I store 1 as a int8,
why did it give me 513 when outputted?

0
Reply mrmikemiller 4/2/2009 5:40:04 PM

mrmikemiller wrote:
> Sorry, I'm learning. Without casting I got 513 so I type casted it to
> int8 and it's 1(which is what I wanted).  When I store 1 as a int8,
> why did it give me 513 when outputted?

You need to give us more information about what you did. Can you show us 
some code? It certainly sounds like you are not outputting a byte, but 
rather a whole word.

Also, I think you mean decimal 513, not hexadecimal?


Bjarni
-- 

                        INFORMATION WANTS TO BE FREE

0
Reply Bjarni 4/2/2009 11:19:19 PM


On Apr 2, 7:40�pm, mrmikemiller <spamt...@crayne.org> wrote:
> Sorry, I'm learning. Without casting I got 513 so I type casted it to
> int8 and it's 1(which is what I wanted). �When I store 1 as a int8,
> why did it give me 513 when outputted?

This could happen if you store the int8 in some portion of the memory
which
already contains 0x513. I assume you store the int8 "after" getting
the
0x513, and this would explain your output.

If all of this is not the case, I'd say it's just a coincidence. It
would then
help if you provide more details.

--Gabriele

0
Reply Phoenix87 4/3/2009 12:03:18 PM

"mrmikemiller" wrote:

> Sorry, I'm learning. Without casting I got 513 so I type casted it to
> int8 and it's 1(which is what I wanted).  When I store 1 as a int8,
> why did it give me 513 when outputted?

decimal || hex (dword)
 513       00000201
5634       00001602

perhaps your 'output' doesn't even know what int8 means and always
work with 16 or 32 bits (as defined in your header) ?
A byte store will not affect the upper bits of a variable and
will keep previously stored values there ...
So if your compiler don't have any 'out_byte' functions
an AND 0000000FFh may do what you want.

__
wolfgang






0
Reply Wolfgang 4/3/2009 2:05:40 PM

mrmikemiller <spamtrap@crayne.org> wrote:
>
>Sorry, I'm learning. Without casting I got 513 so I type casted it to
>int8 and it's 1(which is what I wanted).  When I store 1 as a int8,
>why did it give me 513 when outputted?

"int8" almost certainly means an 8-bit value, not an 8-BYTE value.

513 in decimal is 0x0201 in hex.  When stored in an 8-bit value, you get
0x01.

5634 in decimal is 0x1602 in hex.  When stored in an 8-bit value, you get
0x02.
-- 
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

0
Reply Tim 4/5/2009 4:18:49 AM

4 Replies
151 Views

(page loaded in 0.047 seconds)

Similiar Articles:

7/22/2012 11:12:52 AM


Reply: