Boost logo

Boost Users :

Subject: Re: [Boost-users] reinterpret_cast boost integer
From: Brian Budge (brian.budge_at_[hidden])
Date: 2012-02-05 10:49:30


On Sun, Feb 5, 2012 at 7:06 AM, Brad Tilley <kj4eit_at_[hidden]> wrote:
> I can make the cast work by storing it in a uint16_t or larger type:
>
> void process_uint8_t( const std::string& bytes )
> {
>    const boost::uint16_t * data_ptr;
>    boost::uint16_t data;
>
>    data_ptr = reinterpret_cast<const boost::uint16_t*>(bytes.data());
>    data = *data_ptr;
>
>    std::cout << data << "," << sizeof(data) << std::endl;
> }
>
> I thought this would work in a uint8_t as well, but it doesn't.
>
> Thanks,
>
> Brad
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users

What doesn't work about it? The std iostreams print char types as
(extended) ascii characters. What if you cast the type to a wider
integer just when printing?

  Brian


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net