Didactic Bytes

Discussion of challenges you have already solved
Post Reply
TMBest
Posts: 1
Joined: Thu Aug 20, 2009 1:32 am

Didactic Bytes

Post by TMBest »

199*256*256+77*256+202
TechnoDemon
Posts: 20
Joined: Tue Apr 13, 2010 7:48 am
Location: Makassar, ID

Re: Didactic Bytes

Post by TechnoDemon »

TMBest wrote:199*256*256+77*256+202
what r u talking about??
hex consist only 00 - FF = 0 - 255, so it means there's no 256
No Pain = Gain
That's how programmer develops...
User avatar
CodeX
Posts: 350
Joined: Fri Oct 17, 2008 5:28 pm

Post by CodeX »

There's 256 values you can store though, 1-255 is 255 values and 0 is one more so you have 256. Some abstract number theory:
largest value representable: r^d-1
number of values representable: r^d
where r is the radix/root/base (i.e. 2) and d is the number of digits (i.e. 8) so for a binary byte:
2^8-1 = 255
2^8 = 256
just as with decimal you have
10^3-1 = 999
10^3 = 1000

also looking at the post it looks like TMBest is creating a 3 byte value
0xc74dca
go figure
TechnoDemon
Posts: 20
Joined: Tue Apr 13, 2010 7:48 am
Location: Makassar, ID

Post by TechnoDemon »

from what TMBest wrote, there are several possible results coz he wrote no brackets, i couldn't figure which op to execute first:
199*256*256+77*256+202
=> (199*256) * (256+77) * (256+202)
=> 50944 * 333 * 458
=> 7769673216
is different if brackets move one step to the right:
=> 199 * (256*256) + (77*256) + 202
=> 199 * 65536 + 19712 + 202 'even this can result more possibilities (vb mode = ON)
=> if (199 * 65536) + 19712 + 202 = 13041664 + 19914 = 13061578
=> else 199 * (65536+19712+202) = 199 * 85450 = 17004550
and other possibilities.

CONFUSED ::sighs::
even processor will be confused if there's no operation's priority (i mean 'brackets')
No Pain = Gain
That's how programmer develops...
User avatar
CodeX
Posts: 350
Joined: Fri Oct 17, 2008 5:28 pm

Post by CodeX »

... did you ever go to school?
TechnoDemon
Posts: 20
Joined: Tue Apr 13, 2010 7:48 am
Location: Makassar, ID

Post by TechnoDemon »

oh...
my bad...

I forgot that multiply op is cumulative ( (a*b)*c=a*(b*c) )
this hacker.org's challenges makes me think to complicated.

Btw, thx for the advise, but i'm an university student and almost got my S.E (Sarjana Ekonomi = Bachelor of Economy in Indonesia). I appreciate it...
No Pain = Gain
That's how programmer develops...
User avatar
CodeX
Posts: 350
Joined: Fri Oct 17, 2008 5:28 pm

Post by CodeX »

I can see why there's a global recession
Karian
Posts: 75
Joined: Wed Jan 09, 2008 10:21 am

Post by Karian »

TechnoDemon wrote:I forgot that multiply op is cumulative ( (a*b)*c=a*(b*c) )
I guess you mean it is associative?
TechnoDemon
Posts: 20
Joined: Tue Apr 13, 2010 7:48 am
Location: Makassar, ID

Post by TechnoDemon »

@CodeX
hahahaha... just forget about it, it's a shame

@Karian
that's what i mean... forgive my poor english...
No Pain = Gain
That's how programmer develops...
DragonEgghead
Posts: 3
Joined: Wed May 02, 2012 7:50 pm

Post by DragonEgghead »

Python:

Code: Select all

int(''.join("%08d"%int(bin(i)[2:]) for i in [199, 77, 202]),2)
255 character limit for signatures. Almost enough to display each ASCII character exactly twice (if all characters printed). One less than enough to display every character in ANSI exactly once (again, if all printed). Also, the number of characters here.
lortedy
Posts: 4
Joined: Thu May 03, 2012 9:49 pm

Post by lortedy »

Convert each number from decimal to binary using "calc.exe":

Code: Select all

		199 = 11000111
		  77 = 1001101
		202 = 11001010

Append a 0 at the beginning of 77's binary value.
Concat the 3 values => 110001110100110111001010
Convert binary to decimal => 13061578

Python:

Code: Select all

def binary2decimal(binaryNumber):
	multiplier = 0
	number = 0
	for el in binaryNumber[::-1 ]:
		number += int( el ) * ( 2**multiplier )
		multiplier += 1
	return number

def decimal2binary(decimalNumber):
	bStr = ''
	if decimalNumber < 0: raise ValueError, "Must be a positive integer."
	if decimalNumber == 0: return '0'
	while decimalNumber > 0:
		bStr = str(decimalNumber % 2) + bStr
		decimalNumber = decimalNumber >> 1
	return bStr

a, b, c = 199, 77, 202
a, b, c = decimal2binary(a), decimal2binary(b), decimal2binary(c)
b = '0'+b # Add a leading 0 to binary value of 77 as it has only 7 bits (not a complete byte)
val = ''
val = a+b+c

print binary2decimal(val)
=> 13061578
Post Reply