Kairos
link
fedilink
56M

Bit shifting works if you wanna divide by 2 only.

@PowerCrazy@lemmy.ml
link
fedilink
English
26M

interesting, so does the computer have a special “base 10” ALU that somehow implements division without bit shifting?

In general integer division is implemented using a form of long division, in binary. There is no base-10 arithmetic involved. It’s a relatively expensive operation which usually requires multiple clock cycles to complete, whereas dividing by a power of two (“bit shifting”) is trivial and can be done in hardware simply by routing the signals appropriately, without any logic gates.

@PowerCrazy@lemmy.ml
link
fedilink
English
16M

In general integer division is implemented using a form of long division, in binary.

The point of my comment is that division in binary IS bitshifting. There is no other way to do it if you want the real answer. You can estimate, you can round, but the computational method of division is done via bitshifting of binarary expansions of numbers in an ALU.

Create a post

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

  • Posts must be relevant to programming, programmers, or computer science.
  • No NSFW content.
  • Jokes must be in good taste. No hate speech, bigotry, etc.
  • 1 user online
  • 120 users / day
  • 257 users / week
  • 744 users / month
  • 3.72K users / 6 months
  • 1 subscriber
  • 1.48K Posts
  • 32.5K Comments
  • Modlog