>From: [EMAIL PROTECTED]
>Subject: [REBOL] Writing to a half-byte
>Date: Thu, 13 Jul 2000 13:48:37 -0800
>
>In Assembler class we called a *niblet*
>the lower- or higher- order 4 bits in
>a byte. I'd like a function that would
>would write a niblet in a char! type.
>It would something like this:
>
> >>niblet/low #"a" 2    ; write 0010 to low-order "niblet"
>==#"b"                 ; changed low-order "niblet" = 2
> >>niblet/high #"b" 7   ; write 0111 to high-order "niblet"
>== #"r"                ; r is ascii 72

Well, this function is kinda ugly and could probably be done MUCH better, 
but it works:

niblet: func [ base new /low /high ] [
   either high [
      or~ (and~ base to-char 15)
         to-char (16 * to-integer and~ new to-char 15)
      ][
      or~ (and~ base to-char 240) (and~ new to-char 15)
      ]
   ]

I've been meaning to write decent functions for doing binary manipulations 
in REBOL but I haven't had time yet,  but when I do I'll post them on 
rebol.org (and maybe to the list)

Hope this helps,

   Cal Dixon ([EMAIL PROTECTED])
   -><-

>This is for a high-school course that I'm designing as
>an intro to programming using rebol.
>
>Thanks:
>-Tim
>
>

________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com

Reply via email to