Skip to content

Tarik Billa

  • Web Development
    • html
    • vue.js
    • laravel
    • css
    • javascript
    • jquery
    • node.js
    • php
    • asp.net
  • Programming
    • python
    • java
    • c
    • c++
    • c#
  • git
  • android

exponentiation

How to do exponentiation in clojure?

December 16, 2022 by Tarik

classic recursion (watch this, it blows stack) (defn exp [x n] (if (zero? n) 1 (* x (exp x (dec n))))) tail recursion (defn exp [x n] (loop [acc 1 n n] (if (zero? n) acc (recur (* x acc) (dec n))))) functional (defn exp [x n] (reduce * (repeat n x))) sneaky (also blows … Read more

Categories clojure Tags clojure, exponentiation Leave a comment

The most efficient way to implement an integer based power function pow(int, int)

October 1, 2022 by Tarik

Exponentiation by squaring. int ipow(int base, int exp) { int result = 1; for (;;) { if (exp & 1) result *= base; exp >>= 1; if (!exp) break; base *= base; } return result; } This is the standard method for doing modular exponentiation for huge numbers in asymmetric cryptography.

Categories c Tags algorithm, c++, exponentiation, math Leave a comment

What does the ^ operator do in Java?

September 28, 2022 by Tarik

The ^ operator in Java ^ in Java is the exclusive-or (“xor”) operator. Let’s take 5^6 as example: (decimal) (binary) 5 = 101 6 = 110 —————— xor 3 = 011 This the truth table for bitwise (JLS 15.22.1) and logical (JLS 15.22.2) xor: ^ | 0 1 ^ | F T –+—– –+—– 0 … Read more

Categories java Tags exponentiation, java, operators Leave a comment
Newer posts
← Previous Page1 Page2

Tarik Billa

Software Engineer
tarikbilla@gmail.com
+8801884414000
  • Reuse a hash in YAMLApril 17, 2024
  • Dockerfile: how to redirect the output of a RUN command to a variable?April 16, 2024
  • How to cd to a directory with spaces in the directory name?April 16, 2024
  • Maximum MIME type length when storing the type in a databaseApril 16, 2024
  • What is the difference between Unit, Integration, Regression and Acceptance Testing?April 16, 2024
© 2026 Tarik Billa