Page 2 of 2

Posted: Sun Jul 25, 2010 3:50 pm
by 0042
...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?

Posted: Sun Jul 25, 2010 5:34 pm
by CodeX
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:

Code: Select all

digit(value, number, radix) :=
        floor(value % (radix ^ number)) / (radix ^ (number - 1))
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.

Code: Select all

a % b
is the same as

Code: Select all

a - floor(a / b) * b
for hexadecimal the radix is 16. You can work out quickly in advance how many digits there will be from

Code: Select all

ceil(log(value) / log(radix))
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:

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)
this code prints
[9, 1, 13]
[0]
[1, 0, 0]
[1, 0]
so hex versions would be 0x91d, 0x0, 0x100 and 0x10.

simples! If you find this hard to understand consider it a part of the challenge.

Posted: Sat Jul 31, 2010 8:57 pm
by 0042
Thanks CodeX! I'll take another look at it when I'm more awake.

Posted: Fri Oct 08, 2010 12:12 am
by Bliss
I solved it without using hex values. Everybody did the first step right that is to convert the 3 numbers into bytes. The second step isn't difficult , but not everyone will think of it.
Think Bits.

Posted: Sat Jul 16, 2011 10:48 pm
by Sairera
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!
-しあ

Posted: Sun Jul 17, 2011 8:55 pm
by laz0r
PM'ed to you :)

Posted: Fri Oct 28, 2011 4:23 am
by bemyfriend4397
:? all with genius mind accept me... :lol: :lol: :lol: