Shop OBEX P1 Docs P2 Docs Learn Events
Inverting a 4 bit Value using BITWISE NOT- Troubles — Parallax Forums

Inverting a 4 bit Value using BITWISE NOT- Troubles

DavidMDavidM Posts: 630
edited 2010-06-13 02:00 in Propeller 1
Hi,

I have a value that is stored as a long variable in the range 1 to 10

I then need to INVERT That value as bits, but only the first 4 bits

eg, 1 = 0001 which needs to be inverted to "1110"
3 = 0011 which needs to be inverted to "1100"
9 = 1001 which needs to be inverted to "0110"

If I use the BITWISE NOT function ( i.e !) I think that all the "other" Bits 4-15 are being inverted to 1's

eg, 1 = 00000000_00000000_00000000_00000001

becomes 11111111_11111111_11111111_11111110 after I invert it

but I want it to be 00000000_00000000_00000000_00001110 , I only want the first 4 bits to be inverted


Any ideas?


Thanks
Dave M

Comments

  • BeanBean Posts: 8,129
    edited 2010-06-13 01:14
    Dave,
    XOR it with 15.

    Bean

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Use BASIC on the Propeller with the speed of assembly language.
    PropBASIC thread http://forums.parallax.com/showthread.php?p=867134

    March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    There are two rules in life:
    · 1) Never divulge all information
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    If you choose not to decide, you still have made a choice. [noparse][[/noparse]RUSH - Freewill]
  • DavidMDavidM Posts: 630
    edited 2010-06-13 02:00
    HI Bean,


    That worked!!

    Thanks

    Dave M
Sign In or Register to comment.