Implement `String.eight_bit_signed_number?` (Ruby), `String.eightBitSignedNumber()` (Python), `eight_bit_signed_number()` (JS) or `StringUtils.isSignedEightBitNumber(String)` (Java) which should return `true/True` if given object is a number representable by 8 bit signed integer (-128 to -1 or 0 to 127), `false/False` otherwise.

It should only accept numbers in canonical representation, so no leading `+`, extra `0`s, spaces etc.

Source: codewars | Difficulty: EASY
Tags: Bit manipulation

Fundamentals

Starter code: def signed_eight_bit_number(number):
	

Solutions:
import re

def signed_eight_bit_number(number):
	return bool(re.match('(0|-128|-?([1-9]|[1-9]\\d|1[01]\\d|12[0-7]))\\Z', number))


def signed_eight_bit_number(number):
	if number in list(map(str, list(range(-128, 128)))):
		return True
	return False


import re
SIGNED_BYTE_PATTERN = re.compile('\n    \\A\n    (?:\n        0 |\n        -? (?:\n            1 (?:\n                [01] \\d? |\n                2 [0-7]? |\n                [3-9] )? |\n            [2-9] \\d? ) |\n        -128 )\n    \\Z\n', re.X)

def signed_eight_bit_number(number):
	return bool(SIGNED_BYTE_PATTERN.search(number))


def signed_eight_bit_number(s):
	try:
		return -128 <= int(s) <= 127 and str(int(s)) == s
	except ValueError:
		return False


import re

def signed_eight_bit_number(n):
	return bool(re.fullmatch('-?(1[01]\\d|12[0-7]|[1-9]\\d)|-(128|[1-9])|\\d', n))


import re

def signed_eight_bit_number(n):
	return re.match('-?\\d+$', n) and str(int(n)) == n and (-128 <= int(n) < 128) or False


def signed_eight_bit_number(number):
	return number in list(map(str, list(range(-128, 128))))


def signed_eight_bit_number(number):
	try:
		i = int(number)
		return -128 <= i <= 127 and number == str(i)
	except:
		pass
	return False


import re

def signed_eight_bit_number(number):
	return bool(re.fullmatch('(-?(1(([2][0-7])|([01]\\d))|[1-9][0-9]))|\\d|-[1-9]|-128', number))