[Tutor] Fwd: how to see a number as two bytes

shawn bright nephish at gmail.com
Mon Oct 20 18:20:11 CEST 2008


jeez, i screwed up, i ment num = 600, not 6
thanks

On Mon, Oct 20, 2008 at 11:16 AM, Luke Paireepinart
<rabidpoobear at gmail.com> wrote:
> No, I'm not sure what you mean.
> Given this number
>
> 100101010101101011
>
> the operation will slice off bits on the left with the % 2**16 so that
> we only have 16 bits,
> 0101010101101011
> then it will shift this value to the right so that we only have the
> highest 8 bits
> 01010101
> that will be stored in high.
> Then it will slice off the bits on the left with the 2**8 so that we
> only have 8 bits left,
> 01101011
> and that is your low value.
>
> On Mon, Oct 20, 2008 at 11:04 AM, shawn bright <nephish at gmail.com> wrote:
>> so using this, if num ==6, then i should get 2 and 88 ?
>> thanks, just checking to make sure i get what you wrote.
>> shawn
>>
>> On Mon, Oct 20, 2008 at 11:00 AM, Luke Paireepinart
>> <rabidpoobear at gmail.com> wrote:
>>> ---------- Forwarded message ----------
>>> From: Luke Paireepinart <rabidpoobear at gmail.com>
>>> Date: Mon, Oct 20, 2008 at 11:00 AM
>>> Subject: Re: [Tutor] how to see a number as two bytes
>>> To: shawn bright <nephish at gmail.com>
>>>
>>>
>>> high, low = ((num % 2**16) >> 8, num % 2**8)  or something thereabouts.
>>>
>>> On Mon, Oct 20, 2008 at 10:47 AM, shawn bright <nephish at gmail.com> wrote:
>>>> hey there all,
>>>> i have a script that needs to send a number as two bytes.
>>>> how would i be able to see a number expressed as a hi byte and a lo byte?
>>>>
>>>> thanks
>>>> shawn
>>>> _______________________________________________
>>>> Tutor maillist  -  Tutor at python.org
>>>> http://mail.python.org/mailman/listinfo/tutor
>>>>
>>> _______________________________________________
>>> Tutor maillist  -  Tutor at python.org
>>> http://mail.python.org/mailman/listinfo/tutor
>>>
>>
>


More information about the Tutor mailing list