CREATE OR REPLACE FUNCTION bin2dec (binval in char) RETURN number IS i number; digits number; result number := 0; current_digit char(1); current_digit_dec number; BEGIN digits := length(binval); for i in 1..digits loop current_digit := SUBSTR(binval, i, 1); current_digit_dec := to_number(current_digit); result := (result * 2) + current_digit_dec; end loop; return result; END bin2dec; / SQL> SELECT bin2dec('10110') FROM dual;
BIN2DEC('10110') ---------------- 22
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