Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def print(val : Int)
- hex = true
- sign = val
- arr = uninitialized UInt8[19]
- accum = 0
- if sign < 0
- val = 0 - val
- end
- lut = StaticArray[
- '0', '1', '2', '3',
- '4', '5', '6', '7',
- '8', '9', 'A', 'B',
- 'C', 'D', 'E', 'F'
- ]
- while true
- arr[accum] = lut[(val.to_u % 16)].ord.to_u8
- val = val.to_u / 16
- accum += 1
- break if val == 0
- end
- if hex
- arr[accum + 0] = 'x'.ord.to_u8
- arr[accum + 1] = '0'.ord.to_u8
- accum += 2
- end
- if sign < 0
- arr[accum] = '-'.ord.to_u8
- accum += 1
- end
- arr[accum] = '\0'.ord.to_u8
- i = 0
- j = accum - 1
- while i < j
- c = arr[i]
- arr[i] = arr[j]
- arr[j] = c
- i += 1
- j -= 1
- end
- accum.times do |i|
- Terminal.write_byte arr[i]
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement