Hacker News new | past | comments | ask | show | jobs | submit login
Programmer's Calculator (embeddedrelated.com)
1 point by gregorymichael on June 30, 2017 | hide | past | favorite | 1 comment



POSIX syntax, entered into BusyBox shell (not even Bash or anything), running __on__ an ARM embedded system:

  # echo $(( (0x0110 << 14) & 0xDEADBEEF ))
  262144
  # printf "%x\n" 262144
  40000
Now let's make a calculator REPL out of these:

  # while read expression ; do eval "result=\$(( $expression ))"; printf "dec = %d, hex = %x\n" $result $result ; done
  2 + 2
  dec = 4, hex = 4
  a=3
  dec = 3, hex = 3
  b=4
  dec = 4, hex = 4
  a + b
  dec = 7, hex = 7
  (a + b) << 3 
  dec = 56, hex = 38
  [Ctrl-D][Enter]
  #




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: