[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re:Convert a number to its binary representation (not string) as 1D Vect
From: |
Muthiah Annamalai |
Subject: |
Re:Convert a number to its binary representation (not string) as 1D Vector |
Date: |
Tue, 10 Oct 2006 09:51:30 -0500 |
Hello there,
A nice way of obtaining bitvector representation from a number
could be like this:
#Let N be some number.
#Let L be the bitlength for floor(log2(N))
twos_pow=2.^(L:-1:0)
bitvec=(bitand(N,twos_pow) == twos_pow);
This seemingly avoids user-level loops.
Thanks
Muthu
PS: Sorry for re-opening the old thread, just thought this was cool.
- Re:Convert a number to its binary representation (not string) as 1D Vector,
Muthiah Annamalai <=