• Post Reply Bookmark Topic Watch Topic
  • New Topic

Bitwise Operators  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am incredibly new to Java and am having trouble understanding Bitwise Operators. I have an assignment that I have a few questions.

"Write Java statements using the above variables to assign ONLY bits 7, 6, 5, 4 of num1 to bits 11, 10, 9, 8 of num2 (where bit 0 is the right-most least significant bit). The rest of the bits in num2 should be 0, and DON'T CHANGE num1. You MUST use one of the shift operators, as well as one of the logical bitwise operators."

Above is my assignment and I am having trouble figuring out how exactly I start. What exactly does something like "0xFEDC" or "0x0D00" From what I understand after the X wherever there is a letter there is basically a set of 4 binary numbers, whereas when it is a 0, all 4 of the numbers are 0. Can anyone help me understand what exactly these means and how to start with this assignment?

Thank You.
 
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Do you understand hexadecimal numbers? Do you understand binary numbers? And how to convert between the two?  At minimum, you need to understand this math, to work out this assignment.

Henry
 
Marshal
Posts: 56608
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

If you have used lots of binary arithmetic and often used the bitwise operators, then that exercise will be by no means difficult. If you haven't, I am surprised that you say it is being required of beginners.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!