BAND


Language operator BAND


10
20  a BAND b
30
Bitwise AND.


See examples


If there is insufficient information on this page and you wish learn more about BAND, please send an email to smallbasic@gmail.com. You can help to improve information about BAND by submitting an article using the comments link below. Note, an offline language reference text file is now avialable – see the Download section.

Comments


Def shl(n, c) = n * Pow(2, c) ' shift-left c bits in n
Def shr(n, c) = n \ Pow(2, c) ' shift-right c bits in n
Def mask(c) = Pow(2, c) - 1 ' return a mask of c bits

' get the current date as three integers:
now = Date ' now is "dd/mm/yyyy"
day = Left(now, 2) * 1
month = Mid(now, 4, 2) * 1
year = Right(now, 4) * 1

' pack the date in one integer:
p = day ' packing 5 bits (days 1..31)
p = shl(p, 4) Bor month ' packing 4 bits (months 1..12)
p = shl(p, 12) Bor year ' packing 12 bits (years 0..4095)

Print Using "The current date : 00/00/0000"; day, month, year;
Print " -> Packed as: "; p; " (0x"; Hex(p); ")"

' unpack the date from one integer:
p_day = shr(p, 12 + 4) ' packed in bits 16..20
p_month = shr(p, 12) Band mask(4) ' packed in bits 12..15
p_year = p Band mask(12) ' packed in bits 0..11

Print Using "The Unpacked date: 00/00/0000"; p_day, p_month, p_year;
Pause