CREATE OR REPLACE FUNCTION dec2bin (N in number) RETURN varchar2 IS
binval varchar2(64);
N2 number := N;
BEGIN
while ( N2 > 0 ) loop
binval := mod(N2, 2) || binval;
N2 := trunc( N2 / 2 );
end loop;
return binval;
END dec2bin;
/
SQL> SELECT dec2bin(22) FROM dual;
DEC2BIN(22)
----------------
10110
Simple decimal to binary conversion table:
Decimal | Binary |
---|---|
0 | 0000 0000 |
1 | 0000 0001 |
2 | 0000 0010 |
3 | 0000 0011 |
4 | 0000 0100 |
5 | 0000 0101 |
6 | 0000 0110 |
7 | 0000 0111 |
8 | 0000 1000 |
9 | 0000 1001 |
10 | 0000 1010 |
Nenhum comentário :
Postar um comentário