#!/bin/bash #declare -i ivalue=0x12345679 str_value="0x00FFAA55" declare -i ivalue=0xFFFF55AA declare -i ivalue_rev=$((~ivalue & 0xFFFFFFFF)) declare -i mask=0x03 declare -i alig_len=$(($mask + 1)) declare -i more_len=$(($ivalue & $mask)) declare -i fill_len=$((${alig_len} - $more_len)) declare -i i_str_value=$str_value echo "mask=$mask, alig_len=$alig_len, fill_len = $fill_len, more_len=$more_len" echo "i_str_value=$i_str_value, str_value=$str_value" printf "i_str_value= 0x%08X\n" $i_str_value if [ "$((~ivalue_rev & 0xFFFFFFFF))" = "$((ivalue & 0xFFFFFFFF))" ] ; then echo "OKKKKK" else echo "FAILED" fi printf "value = 0x%08X, ivalue_rev=0x%08X\n" $ivalue $ivalue_rev printf "value = %08X, ivalue_rev=%08X\n" $ivalue $ivalue_rev read_i="FFFF55AA" read_i_rev="0000AA55" declare -i read_ivalue="0x${read_i}" declare -i read_ivalue_rev="0x${read_i_rev}" printf "read_ivalue= 0x%08X, read_ivalue_rev=0x%08X\n" $read_ivalue $read_ivalue_rev printf "read_ivalue=*x%02X*x%02X*x%02X*x%02X, read_ivalue_rev=0x%08X\n" $((((read_ivalue & 0xFF000000) >> 24) & 0xFF)) $((((read_ivalue & 0x00FF0000) >> 16) & 0xFF)) $((((read_ivalue & 0x0000FF00) >> 8) & 0xFF)) $((((read_ivalue & 0x000000FF) >> 0) & 0xFF)) $read_ivalue_rev #echo $ivalue > 1.dat
本文出自 “枪炮与玫瑰的BLOG” 博客,请务必保留此出处http://axlrose.blog.51cto.com/434566/1355481