Jump to content
aXXo

C/c++

Recommended Posts

apa yg dimaksudkan dengan contoh ne :-

example code :

if ((Opcode >> 4) & 0xf) <-- ???

{

-....

}

explaination :

00110010 - some opcode

00000011 - some opcode shifted right (>>) 4 bits

& 00001111 - & 0xF

----------

00000011 - result

aku kurang faham ler! tolong terangkan! macam mana boleh dapat output tu? opcode tu ape?

Edited by aXXo

Share this post


Link to post
Share on other sites

opcode tu ialah real machine language dalam binary. tapi biasanya opcode ditulis dalam hexadecimal sebab binary panjang sangat.

ok dah faham maksud opcode! tp dr explaination yg diberi oleh dlm cth tu mcm mane?

p/s tu explaination aku dpt dr member tp kurang jelas? maksudnya aku tak faham ler hehehe

Share this post


Link to post
Share on other sites

An explanation:

1. Opcode >> 4

-shift Opcode to the right by 4 bits

-kalauvalue Opcode ialah 00110010

1st shift is 00011001

2nd shift is 00001100

3rd shift is 00000110

4th shift is 00000011

so final result of Opcode is 00000011

2. Opcode & 0xF

- operand AND bagi value 00000011 dan 00001111

so

00000011

& 00001111

-------------

00000011

Share this post


Link to post
Share on other sites

opcode means operation code.. biasanya digunakan untuk low level language (i.e assembly language). setiap pemproses memahami set suruhan yang telah dibina ke dalamnya. Suruhan2 ini mempunyai encoding yg tertentu yg dipanggil opcode. Oleh kerana ia hanyalah nombor binary, maka instruction mnemonic dicipta untuk mewakili opcode tersebut.

Kalau dalam bahasa manusia, kod

if ((Opcode >> 4) & 0xf)

bermakna dia nak check bit ke-4 hingga bit ke-7 dalam Opcode samada ia 0 atau tidak. Jika tidak, maka blok dalam if akan dilaksanakan.

Share this post


Link to post
Share on other sites

An explanation:

1. Opcode >> 4

-shift Opcode to the right by 4 bits

-kalauvalue Opcode ialah 00110010

1st shift is 00011001

2nd shift is 00001100

3rd shift is 00000110

4th shift is 00000011

so final result of Opcode is 00000011

2. Opcode & 0xF

- operand AND bagi value 00000011 dan 00001111

so

00000011

& 00001111

-------------

00000011

thanks that really a professional comment :lol:

now i'm pretty much understand how to use bitwise operation!

hat off to you 'BRO :D

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...