DBAsupport.com Forums - Powered by vBulletin
Results 1 to 3 of 3

Thread: Binary Data

  1. #1
    Join Date
    Jan 2000
    I like to store data in o/1 format.
    eg. I need to values from 5 columns in one column.
    I've parameters p1...p5... and value could be either 0 or 1.
    So eg. if I want to store p1=1, p2=0,p3=1,p4=1,p5=0 ....
    and I want to store these values in one column like 10110.
    What datatype shd I use ???
    If I use number is there way to store this type of data.

  2. #2
    Join Date
    Sep 2000
    I haven't ever used bit maps in Oracle, but you can certainly use a number to store the bits. A "number" data type is actually a decimal integer, but the conversion beteen decimal and binary is simple. If their isn't a delivered function to test whether or not a bit is set, you could always write a PL/SQL function to test for it. Setting and clearing the bits are easy. Just set the variable to 0 (zero) to clear all bits, and set individual bits by adding the decimal equivalent to the current value. For example, val = 0 clears all bits; val = 1 sets bit 0; val = 2 sets bit 1; val = 4 set bit 2; val = 1 + 4 sets bit 0 and bit 2; etc. In your example, you would set the first, second and fourth bits, which is the same as setting val = 2^1 + 2^2 + 2^4 (or val = 2 + 4 + 16).

  3. #3
    Join Date
    Sep 2000
    Whoops ....

    I was looking at the bit stream without comparing it to your text. The least significant (zero) bit for binary numbers is typically at the right end, and are read right to left. So the binary number 10110 has bits 1, 2 and 4 set. To set p1, p3 and p4 you would set bits 0, 2 and 3 (or, 01101). Confusing, but that's what computers are for :-)


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width

By using this site, you agree to the Privacy Policy