Just FYI: Recent REBOL's include the ability to perform
       bitwise operations on binary types using AND, OR, and
       XOR.  -jeff

       -------------------------------------------------------

nibble: func [
    a [binary!]  "Binary Byte"
    b [integer!] "0-15"  /high
][a or to-binary to-char either high [b * 16][b]]


comment [ 
    nibble/high #{01} 15 == #{F1}  
    nibble      #{10} 15 == #{1F} 
]


> >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

Reply via email to