1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

(UNO)8ビット機 信号処理用の1/Xの表を作って遊ぶ(固定小数点8,8)(8ビット/8ビット=8ビット)(割り算)

Posted at

目的
入ってきた8ビット信号を増幅では、なく、絞るため

いろいろ
DSPとかの固定小数点用に付いていたり、いなかったりするが
精度が低く独自なため(各社工夫を凝らす)、あまり使われない方法だか
DSPとかの信号処理の場合、処理している間に次の信号が来る為
とりあえず、そこは、そこで速度重視なやり方
(約256バイトぐらい、けちるなと思うが!!!DSP系の命令を付けるなら付けろ、
設計思想に反するなら仕方ない)
(1/2,1/4,1/8して×(掛ける)と言うやり方もある シフトは、さすがに付いている)

割られる数 0...256
割る数  0...256
答え 0...255

範囲を超えた場合は、不定

例外 入力 256は、確認用
例外 割る数 入力 1の時は、そのまま
   (ただし、確認のための入力 256の時は、255を返す)
例外 割る数 0の時は、1で割る時と同じ(そのまま)

表の使い方(遊び方)

x = 割られる数
y = 割る数
z = 答え

z = (x * u[y])>>8;
(x,y,z共に16ビットに拡張(強制キャスト)(掛けた時に範囲を超える為))

結果

o_coq341.jpg

プログラム

オンラインコンパイラ


#include <stdio.h>
int main(void){
    // Your code here!
    int s;
    int h=2560;
    int l=10000;
    int y,u,m,p;
    
    printf("{\n");
    p = 0;
    for(int i=0;i<256;i++){
        s = i;
        if(s==0){s=1;};
        
        y = h/s;
        
        u = (y + 0)/10;
        
        m = (256 * u)>>8;
        
        //printf("<2560>/(%d)=[%d] 10000/(%d)=[%d] <<256/(%d)=[%d]>>  256/%d=%d    ",
        //                i,   y,         i,  l/s,          i,   m,        i, 256/s );
        
        if(i==0 || i==1){u=255;}
                        
        if(i != 255){printf("%d,",u);}else{printf("%d ",u);}
        p++;
        if(p >= 8){printf("\n");p=0;}
        
    }
    printf(",1\n"); // /256
    printf("}\n");
}




{
255,255,128,85,64,51,42,36,
32,28,25,23,21,19,18,17,
16,15,14,13,12,12,11,11,
10,10,9,9,9,8,8,8,
8,7,7,7,7,6,6,6,
6,6,6,5,5,5,5,5,
5,5,5,5,4,4,4,4,
4,4,4,4,4,4,4,4,
4,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,
3,3,3,3,3,3,2,2,
2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,
2,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1 
,1
}


1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?