COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### two's complement 8 bit data to decimal

• Email
• Follow

```Hi guys,

does anyone knows how to convert a 8-bit data in the two's complement format back to signed decimal number?

Thanks,

AL
```
 0

See related articles to this posting

```"Albono Bonomi" <alb.bonomi@gmail.com> wrote in message <hn7hvl\$37c\$1@fred.mathworks.com>...
>
> Hi guys,
>
> does anyone knows how to convert a 8-bit data in the two's complement format back to signed decimal number?
>
> Thanks,
>
> AL

Depends on how you currently have it stored. Assuming it is in a double value you can use typecast like this:

d = 255
u8 = uint8(d)
s8 = typecast(u8,'int8')
d = double(s8)

James Tursa
```
 0

```It works, problem solved.
Thank you James.

"James Tursa" <aclassyguy_with_a_k_not_a_c@hotmail.com> wrote in message <hn7joa\$fin\$1@fred.mathworks.com>...
> "Albono Bonomi" <alb.bonomi@gmail.com> wrote in message <hn7hvl\$37c\$1@fred.mathworks.com>...
> >
> > Hi guys,
> >
> > does anyone knows how to convert a 8-bit data in the two's complement format back to signed decimal number?
> >
> > Thanks,
> >
> > AL
>
> Depends on how you currently have it stored. Assuming it is in a double value you can use typecast like this:
>
> d = 255
> u8 = uint8(d)
> s8 = typecast(u8,'int8')
> d = double(s8)
>
> James Tursa
```
 0