Вопрос

If I write

var n = 0x1234

in Javascript, is

n == 4660

always true? The question can also stated this way: Does 0x1234 denote a sequence of bytes with 0x12 being the first and 0x34 being the last byte? Or does 0x1234 denote a number to the base 16 with the left digit being the most signigicant?

In the first case 0x1234 might be 4660 if interpreted as big endian and 13330 if interpreted as little endian.

In the latter case 0x1234 always equals 1 * 4096 + 2 * 256 + 3 * 16 + 4 = 4660.

Это было полезно?

Решение

The 0x notation in JS always represents a number with base 16 with the left digit being the most significant.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top