...math was never my best subject... *holds head*
I DID look at wikipedia. I can't figure out how to convert it myself though, and found a hex/binary/etc converter online. But I tried typing 233 into the 'regular number' area and I got 3 sets of digits in the Hex box!! and what looked to be far too many strings of numbers in the Dec box.
What am I doing wrong? Is it my approach?
"Didactic Bytes" the dust...
Was that number 563? That's 0x233 in decimal...
You can convert numbers using basic calculations and rounding down which is easy enough on a handy calculator. Here's a function that will get you the nᵗʰ digit of a number with any radix you do:floor(x) is just rounding down and is equivalent to round(x - 0.5), % is the modulo operation (modulus in americanish) which is equal to the remainder of division of the two operands e.g. 9 % 8 = 1.is the same asfor hexadecimal the radix is 16. You can work out quickly in advance how many digits there will be from
where ceil(x) is rounding up and equivalent to round(x + 0.5), if you don't have log (logarithms) available you just do a loop until radix ^ number is bigger than value. Here's an example in Python:this code prints
simples! If you find this hard to understand consider it a part of the challenge.
You can convert numbers using basic calculations and rounding down which is easy enough on a handy calculator. Here's a function that will get you the nᵗʰ digit of a number with any radix you do:
Code: Select all
digit(value, number, radix) :=
floor(value % (radix ^ number)) / (radix ^ (number - 1))
Code: Select all
a % b
Code: Select all
a - floor(a / b) * b
Code: Select all
ceil(log(value) / log(radix))
Code: Select all
# this doesn't work with values less than 0
def convert(value,radix):
digits = [] # where the digit values go
digit = 1 # get ready for first one
x = 0 # start at 0 to
while x <= value: # Do this loop while radix ^ digit is less than value
x = radix ** digit # x = radix ^ digit
v = int((value % x) / (radix ** (digit - 1))) # value of digit
digits = [v] + digits # put the current value of digit on list
digit = digit + 1 # get ready to work out next digit
return digits
print convert(2333,16)
print convert(0,16)
print convert(256,16)
print convert(16,16)
so hex versions would be 0x91d, 0x0, 0x100 and 0x10.[9, 1, 13]
[0]
[1, 0, 0]
[1, 0]
simples! If you find this hard to understand consider it a part of the challenge.
I turned the decimals into 8 bit integers and got this:
199=11000111
77=1001101
202=11001010
But can someone please explain to me how to turn those into a 24 bit unsigned integer? I wasn't able to find a reliable explanation online. Thanks!
-しあ
199=11000111
77=1001101
202=11001010
But can someone please explain to me how to turn those into a 24 bit unsigned integer? I wasn't able to find a reliable explanation online. Thanks!
-しあ
I don't suffer from insanity. I enjoy every second of it.