with
data (input1, input2) as (
select 0, 0 from dual union all
select 0, 1 from dual union all
select 1, 0 from dual union all
select 1, 1 from dual
),
data2 as (
select
utl_raw.cast_from_binary_integer(input1) as input1,
utl_raw.cast_from_binary_integer(input2) as input2
from
data
),
-- 半加算器
half_adder as (
select
input1,
input2,
utl_raw.bit_or(
utl_raw.bit_and(
input1,
utl_raw.bit_complement(input2)
),
utl_raw.bit_and(
utl_raw.bit_complement(input1),
input2
)
) as output_sum,
utl_raw.bit_and(input1, input2) as output_carry
from
data2
),
-- 全加算器
full_adder as (
select
ha1.input1 as a,
ha1.input2 as b,
ha2.input2 as x,
utl_raw.bit_or(
ha1.output_carry,
ha2.output_carry
) as c,
ha2.output_sum as s
from
half_adder ha1
inner join half_adder ha2 on
ha1.output_sum = ha2.input1
)
select
to_number(fa.a) as a,
to_number(fa.b) as b,
to_number(fa.x) as x,
to_number(fa.c) as c,
to_number(fa.s) as s
from
full_adder fa
order by
fa.a || fa.b || fa.x
2012年8月21日火曜日
SQLで全加算器
何か奇抜な事をしてみたくて思いついたのが、SQLで全加算器の真理値表を作る事。
登録:
コメントの投稿 (Atom)
SQL で MP4 をパース
SQL でビットマップ画像の2値化は4年位前に挑戦した。 最近、それの Impala 版 を作ったときに閃いた。 「再帰CTEがあるなら、mp4 もいけるんじゃないか」と。 やってみた。 use ragingo drop table video go create...
-
Hyper-V の 仮想マシン起動時のエラー 32788 に苦しめられたけど、イベントログ見れば一瞬で解決できたのでメモ イベントビューアー > アプリケーションとサービスログ > Microsoft > Windows > Hyper-V-**** ...
-
HTML1枚にぎゅっと詰まったシェーダー練習帳 gist https://gist.github.com/ragingo/e9edf399419dd90bd2894de9f48f6710 フラグメントシェーダーが終わったら、 今度は頂点シェーダーをやろう。
-
以前やったSQLでの画像処理(2値化)です。 master.dbo.fn_varbintohexsubstring が遅すぎるから、そこだけ c# で対応しました。 処理前 処理後(SSMS -> Excel) use sample go --...
0 件のコメント:
コメントを投稿