Click here to Skip to main content
15,914,160 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: CharToInt Pin
OriginalGriff17-Apr-09 22:39
mveOriginalGriff17-Apr-09 22:39 
JokeRe: CharToInt Pin
Paulo Zemek18-Apr-09 12:51
Paulo Zemek18-Apr-09 12:51 
GeneralRe: CharToInt [modified] Pin
OriginalGriff18-Apr-09 22:10
mveOriginalGriff18-Apr-09 22:10 
GeneralRe: CharToInt Pin
OriginalGriff18-Apr-09 22:12
mveOriginalGriff18-Apr-09 22:12 
GeneralRe: CharToInt Pin
Paulo Zemek20-Apr-09 0:53
Paulo Zemek20-Apr-09 0:53 
GeneralRe: CharToInt Pin
riced20-Apr-09 5:05
riced20-Apr-09 5:05 
GeneralRe: CharToInt Pin
Jeroen De Dauw21-Apr-09 3:20
Jeroen De Dauw21-Apr-09 3:20 
GeneralRe: CharToInt Pin
Lutosław19-Apr-09 1:00
Lutosław19-Apr-09 1:00 
I'm doing A LOT of such stuff nowadays. In assembly. (AT&T syntax)
# READ (char* bufer, int bufer_len)
# Reads a number from an ascii buffer and returns an actual number in eax
#
# PARAMETERS
# 	1. Address to the buffer
# 	2. The string's length
#
# Used registers:
# 	esi - contains all read characters
#	ecx - index inside the buffer
#	ebx - used in a conversion process char -> int
#	edx - address to the buffer
#	eax - the result
.globl read
.type read, @function
read:
	.equ DIGIT_0,'0'
	.equ DIGIT_9,'9'
	.equ CASE_A,'A'
	.equ CASE_F,'F'
	.equ CASE_a,'a'
	.equ CASE_f,'f'
	.equ ONE_DIGIT_MASK, 0x0000000F

	mov 8(%esp), %esi # save number of read chars

	mov $0, %ecx
	mov $0, %eax # there was the zero at the beginnig of the Universe
	cmp %ecx, %esi # empty string case
	je read_done

read_loop:
	mov $0, %ebx

	mov 4(%esp), %edx
	#mov (%edx), %edx	
	mov (%edx, %ecx, 1), %bl # take the next char
	cmp $DIGIT_9, %bl
	jle read_0to9

read_AtoF:
	cmp $CASE_a, %bl
	jge read_AtoF_lowercase
	sub $CASE_A, %bl # substitute'A'
	jmp read_AtoF_continue
read_AtoF_lowercase:
	sub $CASE_a, %bl # substitute 'A'
read_AtoF_continue:
	add $10, %bl # add 10 to get the correct value
	jmp read_char_done

read_0to9:
	cmp $DIGIT_0, %bl
	jl read_done
	sub $DIGIT_0, %bl # substitute '0'
	jmp read_char_done

read_char_done:
	# (bl is a lower part of ebx)
	add %ebx, %eax # ebx is a read-to-eat int
	
	inc %ecx # increment the index
	cmp %ecx, %esi # check if we're done
	je read_done
	
	shl $4, %eax # shift the number by one hex digit capacity.
	
	jmp read_loop
	
read_done:
	ret

OMG | :OMG:

Greetings - Gajatko

Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.

GeneralRe: CharToInt Pin
Brady Kelly24-Apr-09 9:12
Brady Kelly24-Apr-09 9:12 
GeneralRe: CharToInt Pin
Rajesh R Subramanian30-Apr-09 1:09
professionalRajesh R Subramanian30-Apr-09 1:09 
GeneralSetters and Getters evil future [modified] Pin
stanislav.simunec15-Apr-09 23:53
stanislav.simunec15-Apr-09 23:53 
JokeRe: Setters and Getters evil future [modified] Pin
zvjerka2415-Apr-09 23:59
zvjerka2415-Apr-09 23:59 
GeneralRe: Setters and Getters evil future Pin
stanislav.simunec16-Apr-09 3:55
stanislav.simunec16-Apr-09 3:55 
GeneralRe: Setters and Getters evil future Pin
Nagy Vilmos16-Apr-09 11:24
professionalNagy Vilmos16-Apr-09 11:24 
GeneralRe: Setters and Getters evil future Pin
Jeroen De Dauw21-Apr-09 3:43
Jeroen De Dauw21-Apr-09 3:43 
GeneralRe: Setters and Getters evil future Pin
Dan Neely21-Apr-09 4:05
Dan Neely21-Apr-09 4:05 
GeneralRe: Setters and Getters evil future Pin
Nagy Vilmos21-Apr-09 5:54
professionalNagy Vilmos21-Apr-09 5:54 
GeneralRe: Setters and Getters evil future Pin
Dan Neely21-Apr-09 7:10
Dan Neely21-Apr-09 7:10 
GeneralRe: Setters and Getters evil future Pin
Nagy Vilmos21-Apr-09 10:10
professionalNagy Vilmos21-Apr-09 10:10 
GeneralRe: Setters and Getters evil future Pin
Dan Neely21-Apr-09 10:26
Dan Neely21-Apr-09 10:26 
GeneralRe: Setters and Getters evil future Pin
Jeroen De Dauw28-Apr-09 5:58
Jeroen De Dauw28-Apr-09 5:58 
GeneralNot a coding horror as such, but... Pin
OriginalGriff15-Apr-09 8:43
mveOriginalGriff15-Apr-09 8:43 
GeneralRe: Not a coding horror as such, but... Pin
PIEBALDconsult15-Apr-09 10:02
mvePIEBALDconsult15-Apr-09 10:02 
GeneralRe: Not a coding horror as such, but... Pin
Yusuf15-Apr-09 13:17
Yusuf15-Apr-09 13:17 
GeneralRe: Not a coding horror as such, but... Pin
BillW3323-Apr-09 7:18
professionalBillW3323-Apr-09 7:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.