"Didactic Bytes" the dust...

User avatar
0042
Posts: 56
Joined: Wed Jul 14, 2010 11:08 pm
Location: I'm on Skype! PM me for my username!

Post 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?
"If you can read this, you must be really bored!"

Girl Hackers!! Because you don't need a penis to be good with computers!!
-----
Name: Jennifer
Age: 21
Number of n00bz used as cannonfodder: "Now serving #2,364,428!"
User avatar
CodeX
Posts: 350
Joined: Fri Oct 17, 2008 5:28 pm

Post 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.
User avatar
0042
Posts: 56
Joined: Wed Jul 14, 2010 11:08 pm
Location: I'm on Skype! PM me for my username!

Post by 0042 »

Thanks CodeX! I'll take another look at it when I'm more awake.
"If you can read this, you must be really bored!"

Girl Hackers!! Because you don't need a penis to be good with computers!!
-----
Name: Jennifer
Age: 21
Number of n00bz used as cannonfodder: "Now serving #2,364,428!"
Bliss
Posts: 10
Joined: Sat Oct 02, 2010 8:23 pm

Post 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.
Truly yours
Sairera
Posts: 6
Joined: Sun Nov 07, 2010 8:45 pm

Post 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!
-しあ
I don't suffer from insanity. I enjoy every second of it.
User avatar
laz0r
Posts: 290
Joined: Thu Feb 04, 2010 4:18 pm
Location: Within the depths of Unix

Post by laz0r »

PM'ed to you :)
There is no spoon.
bemyfriend4397
Posts: 3
Joined: Tue Oct 18, 2011 3:35 am

Post by bemyfriend4397 »

:? all with genius mind accept me... :lol: :lol: :lol:
Post Reply