1
A
回答
2
這可以幫助你;
#!/bin/bash
input=$1
if [[ $input -lt "0" ]]; then
output=$((4294967296+$input))
else
output=$input
fi
echo $output
#signed int32;
#–2,147,483,648 to 2,147,483,647
#unsigned int32
#0 to 4,294,967,295
1
這裏去,可能不是最快的,但似乎工作
unsigned_to_signed()
{
local hex=$(printf "0x%x" $(($*)))
local unsigned=$(printf "%u" $hex)
echo $unsigned
}
unsigned_to_signed32()
{
local hex=$(printf "0x%x" $(($* & 0xFFFFFFFF)))
local unsigned=$(printf "%u" $hex)
echo $unsigned
}
unsigned_to_signed -256
18446744073709551360
unsigned_to_signed32 -256
4294967040
相關問題
- 1. 從無符號長整型轉換爲無符號整型
- 2. C++算術類型轉換與無符號&符號整數
- 3. 將有符號整數轉換爲無符號長整型的最佳方法?
- 4. 將無符號字符(數組)轉換爲無符號整數(數組)
- 5. shell腳本符號「:>」
- 6. AWK將大無符號整數轉換爲有符號整數(二進制)
- 7. 在無符號整數和有符號整數之間進行C++轉換
- 8. 無符號整數
- 9. 隱式轉換爲無符號類型的負整數
- 10. C將無符號字符轉換爲無符號字符:4
- 11. C++和 - (無符號整型)
- 12. 「Int」和「無符號整型」
- 13. 從無符號轉換爲帶符號的類型安全嗎?
- 14. 將int無效轉換爲無符號整型
- 15. 類型轉換爲無符號用C
- 16. 轉換無符號短於符號短爲音頻PCM樣本
- 17. 我想字符串和整數轉換成無符號字節
- 18. 無符號整型到帶有Python的帶符號浮點數
- 19. C中轉換有符號整數
- 20. 將Ruby符號轉換爲整數
- 21. 不能轉換成符號整數
- 22. 帶符號整數的末端轉換
- 23. 另一個「NSUInteger *」(又名「無符號整數*」)與「NSUInteger」(又名「無符號整型」)
- 24. 什麼發生在整數類型轉換的無符號字符的背景?
- 25. C++將字符串轉換爲16位無符號/有符號整型/浮點型
- 26. 如何從int轉換爲無符號短整型 - iPhone
- 27. 枚舉類「不能轉換爲無符號整型」
- 28. Shell腳本 - 用換行符替換每5個逗號
- 29. 如何將字符串轉換爲shell腳本中的整數?
- 30. C++從無符號的隱式數據類型轉換爲帶符號的
那你試試? –
我試過這樣的負數: SIGNED = -256 UNSIGNED = $((0x'printf'%x'$ SIGNED | grep -Eo'。{8} $'')) – Songe