Jesuraj vinoth wrote:
> --- In [email protected], Thomas Hruska <[EMAIL PROTECTED]> wrote:
>   
>> Jesuraj vinoth wrote:
>>     
>>> I am trying to convert code written in verilog to C. I need to 
>>>       
> convert 
>   
>>> the following line present in verilog to C.  
>>>
>>>  data = { 8'b00000001, a, 1'b0, b, 16'h1234 }
>>>
>>>  were data is 32-bit , a and b are 3 bit. The a and b are given 
>>> different 3 bit values (i.e 0 to 7) down the code.
>>> Can anyone help me on this?
>>>       
>> Bitwise 'or'?
>>
>> data = 0x01000000 | ((a & 0x07) << 4) | 0x00080000 | (b & 0x07) | 
>> 0x00001234;
>>
>> Or something like that.  Although, it appears to be missing a bit 
>> (totals to 31 bits).
>>
>> -- 
>> Thomas Hruska
>> CubicleSoft President
>> Ph: 517-803-4197
>>
>> *NEW* MyTaskFocus 1.1
>> Get on task.  Stay on task.
>>
>> http://www.CubicleSoft.com/MyTaskFocus/
>>
>>     
>
> Thanks Thomas.
> The assignment i used was:
> data = 0x01000000 | ((i & 0x00000007) << 20 ) | ((j & 0x00000007) 
> <<16) | 0x00000050 ;
>
> btw it was 32 bit data.
>
>   
You know, there are "bitfields" both in C and in C++... this allows you 
to specify what looks like a struct and specify how much space you want 
for each field.

Presuming you want to give them names, it would lookd something like;
struct something
{
    int x::8;
    int a:4;
    int b:4;
    int h:16;
;

something yy;
yy.x = 1;
yy.a = 0;
yy.h = 0x1234;

you never did initialize b

the assignment you used below would have been
yy.x = 1;
yy.a = i;
yy.b = j;
yy.h = 0x50;

this should make things a lot more readable.


[Non-text portions of this message have been removed]

Reply via email to