sha265.rb
def bits(x, n = 32)
  if x >= 0
    return x.to_s(2).rjust(n, '0') # "%0#{n}b" % x does not work in Shopify
  else
    # Note: Ruby NOT function returns a negative number, and .to_s(2) displays this mathematical representation in base 2.
    # Note: So to get the expected unsigned notation you need to get the individual bits instead.
    # Note: When doing so, ignore the first bit because that's the sign bit.
    # https://www.calleerlandsson.com/rubys-bitwise-operators/
    return (n - 1).downto(0).map { |i| x[i] }.join
  end
end
# Convert integer to binary string (32 bits) - modified from original
Convert integer to binary string (32 bits) - modified from original
Convert integer to binary string ( 32 bits ) - modified from original
def bits(x, n = 32)
  if x >= 0
    return x.to_s(2).rjust(n, '0') 
  else
    return (n - 1).downto(0).map { |i| x[i] }.join
  end
end
def bits ( x , n = 32 ) if x >= 0 return x . to_s ( 2 ) . rjust ( n , '0' ) else return ( n - 1 ) . downto ( 0 ) . map { | i | x [ i ] } . join end end
Convert integer to binary string (32 bits) - modified from original
Convert integer to binary string ( 32 bits ) - modified from original
# "%0#{n}b" % x does not work in Shopify # Note: Ruby NOT function returns a negative number, and .to_s(2) displays this mathematical representation in base 2. # Note: So to get the expected unsigned notation you need to get the individual bits instead. # Note: When doing so, ignore the first bit because that's the sign bit. # https://www.calleerlandsson.com/rubys-bitwise-operators/
x
n