ForHosting KIT · Developer Utilities

Arithmetic right shift calculator

This arithmetic right shift calculator moves every bit of a signed integer to the right while copying the original most significant bit into the positions opened on the left.

● BetaFree · in your browser
Use it from WebAPIEmailTelegramApp soon

Choose a width, enter a signed decimal, hexadecimal, or binary integer, and specify the shift count. The result includes exact decimal values and width-padded binary patterns, making two’s-complement behavior visible without relying on a programming language’s implicit integer size or numeric limits.

Choose the signed width before shifting

An arithmetic right shift only has a precise meaning when the integer width is known. The same visible low bits can describe a positive value at one width and a negative value at another because the most significant bit is the sign bit in two’s-complement representation. Enter a width from 2 through 1024 bits, then provide a value that fits its signed range. For width w, that range begins at negative 2 raised to w minus 1 and ends at 2 raised to w minus 1, minus one. The calculator rejects values outside that range instead of silently truncating them. This makes the operation suitable for checking instruction behavior, binary protocols, compiler exercises, and code that deliberately works with fixed-size signed integers. Decimal input is often clearest for a negative number, while a 0x or 0b prefix is useful when comparing a register or packet field with documentation. The returned input pattern is padded to the chosen width, so every sign and data bit remains visible.

Understand sign extension in the result

A logical right shift always inserts zeroes on the left. An arithmetic right shift instead repeats the original sign bit: zero for a nonnegative signed value and one for a negative signed value. This repetition is called sign extension. It preserves the sign as bits move toward the least significant position. For nonnegative inputs, arithmetic and logical right shift therefore produce the same pattern. For negative inputs, they differ immediately because the arithmetic operation fills the vacated positions with ones. Numerically, shifting right by n positions behaves like division by 2 raised to n rounded toward negative infinity, not truncation toward zero. For example, negative five shifted right once becomes negative three. The output supplies both the signed decimal result and the complete width-padded result pattern, so you can verify the numeric interpretation and the bit movement together. The `sign_bit` field reports the original sign bit that was replicated, making the distinction explicit even when the shift count is zero.

Handle large shift counts and exact integers

Shift counts may range from zero through 1024. A zero count leaves the value and its bit pattern unchanged. When the count reaches or exceeds the chosen width, every original data bit has moved away; sign extension leaves zero for a nonnegative value and negative one for a negative value. This defined behavior avoids the count masking performed by some processors and languages, where a large count may be reduced modulo a machine-specific amount before execution. All integer parsing and calculation use exact arbitrary-precision integer arithmetic. Results are returned as strings because JSON numbers cannot exactly represent every integer available at widths such as 64, 128, or 1024 bits. This is intentional: consumers should parse the decimal strings with an exact integer type rather than a floating-point number. Use the binary fields when you need a direct visual comparison, and use the decimal `result` when feeding the answer into another exact calculation or a fixed-width test fixture.

Verify signed instruction behavior

Compare an emulator, compiler, or processor result with an explicit fixed-width arithmetic shift.

Debug binary formats

Inspect how a signed field behaves when a protocol decoder applies sign-preserving bit operations.

Teach two’s-complement arithmetic

Show the padded input and output patterns alongside their exact signed decimal interpretations.

What does an arithmetic right shift do?

It moves bits right and fills vacated high positions with copies of the original sign bit.

How is this different from a logical right shift?

A logical shift always inserts zeroes, while an arithmetic shift inserts the sign bit and therefore preserves a negative sign.

Which input formats are accepted?

Use signed decimal text, or add a 0x hexadecimal or 0b binary prefix. A leading plus or minus sign is accepted.

What happens when the shift count is at least the width?

The result is zero for a nonnegative value and negative one for a negative value because only replicated sign bits remain.

Why are decimal values returned as strings?

Strings preserve exact integers beyond JSON’s safe numeric range, including 64-bit and wider values.

What does an API request cost?

Each API request costs $0.002. The browser implementation uses the same deterministic calculation.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/dev/arithmetic-shift-right

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/dev/arithmetic-shift-right \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"value":"-42","width":8,"shift":3}'
{
  "value": "-42",
  "width": 8,
  "shift": 3
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "dev.arithmetic_shift_right",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Read the full KIT documentation →