0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Notion数式で16進数→10進数変換

Last updated at Posted at 2024-05-12

数式

sum(split(prop("入力(16進数)"), "").map(
	ifs(
		current == "A", 10,
		current == "B", 11,
		current == "C", 12,
		current == "D", 13,
		current == "E", 14,
		current == "F", 15,
		current.toNumber()
	) * pow(16, length(prop("入力(16進数)")) - index - 1)
))

image.png

Step By Step

① 文字列を1文字ずつの配列にする

split(prop("入力"),"")

image.png

② 1文字ずつ文字を数値に変換する

split(prop("入力(16進数)"), "").map(
	ifs(
		current == "A", 10,
		current == "B", 11,
		current == "C", 12,
		current == "D", 13,
		current == "E", 14,
		current == "F", 15,
		current.toNumber()
	)
)

image.png

③ 位に合わせて16の累乗を掛ける

split(prop("入力"), "").map(
	ifs(
		current == "A", 10,
		current == "B", 11,
		current == "C", 12,
		current == "D", 13,
		current == "E", 14,
		current == "F", 15,
		current.toNumber()
	) * pow(16, length(prop("入力")) - index - 1)
)

image.png

④ 合算する

sum(split(prop("入力"), "").map(
	ifs(
		current == "A", 10,
		current == "B", 11,
		current == "C", 12,
		current == "D", 13,
		current == "E", 14,
		current == "F", 15,
		current.toNumber()
	) * pow(16, length(prop("入力")) - index - 1)
))

image.png

使用例

16進数のカラーコードを10進数にすることができます。
先頭の#は、toNumberメソッドで値を返さないので無視されます。
image.png

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?