tinyint的取值方法

型態byte範圍
tinyint
tinyint unsigned
1byte-128~127
UNSIGNED: 0~255


tinyint

1byte=8bit
1 111 1111 -> -128
0 111 1111 ->  127
tinyint unsigned
1byte=8bit
0000 0000 ->0
1111 1111->255
例:我以權限來permission
1 代表--新增功能
2 代表--修改功能
4 代表--刪除功能
如果一位使用者的
permission=3
那判斷
permission & 1 = 1
    0000 0011
& 0000 0001
    0000 0001   = 1 成立代是有新增功能
permission & 2 = 2

    0000 0011
& 0000 0010
    0000 0010 = 2 成立代是有修改功能


permission & 4 = 4

    0000 0011
& 0000 0100
    0000 0000 = 0  不成立沒有刪除功能

參考資料






 
















其它文章

arrow
arrow

    PG Levin Li 發表在 痞客邦 留言(0) 人氣()