解决方案 »

  1.   

    no
    but javascript has jsoncolor={r:255,g:127,b:255}
    r=color.r
    g=color.g
    b=color.b
      

  2.   

    这个不是直接赋值了么。我的意思是这样
    var c=0x00ff00;
    color=c;
    color.r;
    这样
      

  3.   


    javascript's bitwise operators, which is as same as your favorite C...
      

  4.   

    c = 0x00ff00;
    color = {'r':c>>16 & 0xff, 'g':c>>8 & 0xff, 'b':c & 0xff};
    {"r":0,"g":255,"b":0}
      

  5.   


    javascript's bitwise operators, which is as same as your favorite C...
    I know the usage of bitwise operators,I just find a simple function or operation to achieve。
      

  6.   

    这每次不都要写一大串么。。Well, you are picky!Then write us the same function in C, show us how short it could be!
      

  7.   


    he's comparing apple with orange,..
      

  8.   

    这每次不都要写一大串么。。Well, you are picky!Then write us the same function in C, show us how short it could be!funny
      

  9.   

    这每次不都要写一大串么。。Well, you are picky!Then write us the same function in C, show us how short it could be!
    union {
        struct  
        {
            unsigned char a1:2;
            unsigned char a2:3;
            unsigned char a3:3;
        }x;
        unsigned char b;
    }d;
    int main(int argc, char* argv[])
    {
        d.b = 100;
        return 0;
    }
    and ,every time ,one line"d.b=100" see?
    and I have just known about this usage two mouth ago.
    easy?ha?
      

  10.   


    See?
    Master Yoda! I didn't know it's you!See what? your "brilliant C codes". Could you please count the number of lines your writing has? So the declaration and definition of the fancy union with embedded struct doesn't count here, does it?I would take your codes as an "example". Because for R, G, B fields in color, each of them can take the value from 0 to 255. That's exactly 1 Byte. In reality, if you want to use this concept, each bit field will have to be defined with :8. It seems to lose the point since the type you defined there is unsigned char, which is exactly 8 bits, huh?More ironically ( I won't even want to touch the portability concerns here.):Whoever taught you this made a mistake:In C and C++ bit fields can be created using unsigned int, signed int, or _Bool (in C99). But you have unsigned char. The behavior is undeterminedThis is the forum for discussing questions for javascript in web development. I tried to remind you that you were comparing oranges with apples, which doesn't make sense for most of cases, especially for comparing the features of programming languages. user "xuzuning " had answered your question. You should take it!Keep challenging or disrespect people who offer help here will only make you awkward. In the end, it exposed your weakness. OK, waste too much time here. I have to mow my F lawn...
      

  11.   


    See?
    Master Yoda! I didn't know it's you!See what? your "brilliant C codes". Could you please count the number of lines your writing has? So the declaration and definition of the fancy union with embedded struct doesn't count here, does it?I would take your codes as an "example". Because for R, G, B fields in color, each of them can take the value from 0 to 255. That's exactly 1 Byte. In reality, if you want to use this concept, each bit field will have to be defined with :8. It seems to lose the point since the type you defined there is unsigned char, which is exactly 8 bits, huh?More ironically ( I won't even want to touch the portability concerns here.):Whoever taught you this made a mistake:In C and C++ bit fields can be created using unsigned int, signed int, or _Bool (in C99). But you have unsigned char. The behavior is undeterminedThis is the forum for discussing questions for javascript in web development. I tried to remind you that you were comparing oranges with apples, which doesn't make sense for most of cases, especially for comparing the features of programming languages. user "xuzuning " had answered your question. You should take it!Keep challenging or disrespect people who offer help here will only make you awkward. In the end, it exposed your weakness. OK, waste too much time here. I have to mow my F lawn...
    well
    Your English is even better than my dialect
    I had to use Chinese。
    恩。。如果我不小心说错了话或者表达的有问题,那么,奉上我最真挚的道歉,谢谢您的嘲讽,这样我可以成长的更快,最开始提这个问题不是为了解决,我只是想知道,既然js这么简便,那么应该也有类似位域的用法,如果有,我就去学习,如果没有,函数也是不错的选择,我并不是怕麻烦,比较一些编程语言的用法总是好的,即巩固了原来的语言,有扩展了自己的认知
    而且,如果程序有几百行,用到位域又有很多次,除了用函数的方法,C之前的定义和声明不是可以忽略不计么,调用10几次,js每次写一大串(在不用函数的情况下),而C每次只用了几个字母。这是我说的简便的地方。。恩。。既然不行,那先谢谢各位大师了。。